Python 入门教程 1 ---- Python Syntax
1 Python是一个高效的语言,读和写的操作都是很简单的,就像普通的英语一样
shells怎么读音2 Python是一个解释执行的语言,我们不需要去编译,我们只要写出代码即可运行
3 Python是一个面向对象的语言,在Python里面一切皆对象
4 Python是一门很有趣的语言
5 变量:一个变量就是一个单词,只有一个单一的值
练习:设置一个变量my_variable,值设置为10
[cpp]
#Write your code below!
html网页特效代码雪花my_variable = 10
3 第三节
1 Python里面有三种数据类型 interage , floats , booleans
2 Python是一个区分大小写的语言
3 练习
1 把变量my_int 值设置为7
2 把变量my_float值设置为1.23
3 把变量my_bool值设置为true
气象python零基础入门教程[python]
#Set the variables to the values listed in the instructions!
my_int = 7
my_float = 1.23
my_bool = True
6 Python的变量可以随时进行覆盖
2 练习:my_int的值从7改为3,并打印出my_int
[python]
#my_int is set to 7 below. What do you think
#will happen if we reset it to 3 and print the result?
my_int = 7
#Change the value of my_int to 3 on line 8!
my_int = 3
#Here's some code that will print my_int to the console:
#The print keyword will be covered in detail soon!
print my_int
7 Pyhton的声明和英语很像
8 Python里面声明利用空格在分开
3 练习: 查看以下代码的错误
[python]
def spam():
eggs = 12
return eggs
print spam() 噼哩噼哩app
9 Python中的空格是指正确的缩进
2 练习: 改正上一节中的错误
[python]
def spam():
eggs = 12
return eggs
print spam()
primary英语怎么读
10 Python是一种解释执行的语言,只要你写完即可立即运行
2 练习:设置变量spam的只为True,eggs的值为False
[python]
spam = True
eggs = False
11 Python的注释是通过“#”来实现的,并不影响代码的实现
2 练习:给下面的代码加上一行注释
[python]
#this is a comments for Python
mysterious_variable = 42
12 Python的多行注释是通过“ """ """ ”来实现的
2 练习:把下面的代码加上多行
[python]
"""
this is a Python course
"""
a = 5
13 Python有6种算术运算符+,-,*,/,**(幂),%
2 练习:把变量count_to设置为1+2
[python]
#Set count_to equal to 1 plus 2 on line 3!
count_to = 1+2
print count_to
14 Python里面求x^m,写成x**m
2 练习:利用幂运算,把eggs的值设置为100
[python]
#Set eggs equal to 100 using exponentiation on line 3!
eggs = 10**2
print eggs
1 练习:
1 写一行注释
2 把变量monty设置为True
3 把变量python值设置为1.234
4 把monty_python的值设置为python的平方
[python]
#this is a Python
monty = True
python = 1.234
monty_python = python**2
Python 入门教程 2 ---- Tip Calculator
1 把变量meal的值设置为44.50
[python]
#Assign the variable meal the value 44.50 on line 3!
meal = 44.50
1 把变量tax的值设置为6.75%
[python]
meal = 44.50
tax = 6.75/100
1 设置tip的值为15%
[python]
#You're almost there! Assign the tip variable on line 5.
meal = 44.50
tax = 0.0675
tip = 0.15
1 把变量meal的值设置为meal+meal*tax
[python]
#Reassign meal on line 7!
meal = 44.50
tax = 0.0675
tip = 0.15
meal = meal+meal*tax
设置变量total的值为meal+meal*tax
[python]
#Assign the variable total on line 8!
meal = 44.50
tax = 0.0675
tip = 0.15
meal = meal + meal * tax
total = meal + meal * tip
print("%.2f" % total)
Python 入门教程 3 ---- Strings and Console Output
15 Python里面还有一种好的数据类型是String
16一个String是通过'' 或者 ""包成的串
3 设置变量brian值为"Always look on the bright side of life!"kalilinux系统
[python]
#Set the variable brian on line 3!
brian = "Always look on the bright side of life!"
1 练习
1 把变量caesar变量设置为Graham
2 把变量praline变量设置为john
3 把变量viking变量设置为Teresa
[python]
#Assign your variables below, each on its own line!
caesar = "Graham"
praline = "John"
viking = "Teresa"
#Put your variables above this line
print caesar
print praline
print viking
17 Python是通过\来实现转义字符的
2 练习把'Help! Help! I'm being repressed!' 中的I'm中的'进行转义
[python]
#The string below is broken. Fix it using the escape backslash!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论