Python 入门教程 1 ---- Python Syntax


1 第一节
    1 Python介绍
       1 Python是一个高效的语言,读和写的操作都是很简单的,就像普通的英语一样
       2 Python是一个解释执行的语言,我们不需要去编译,我们只要写出代码即可运行
       3 Python是一个面向对象的语言,在Python里面一切皆对象
       4 Python是一门很有趣的语言
  
 2 第二节
    1 变量:一个变量就是一个单词,只有一个单一的值
    2 练习:设置一个变量my_variable,值设置为10 
[cpp]  
#Write your code below!  
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]  
#Set the variables to the values listed in the instructions!  
my_int = 7  
my_float = 1.23  
my_bool = True  
 
 4 第四节
    1 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  
 
 第五节
    1 Pyhton的声明和英语很像
    2 Python里面声明利用空格在分开
    3 练习: 查看以下代码的错误
[python]  
def spam():  
eggs = 12  
return eggs   
print spam()  
 
       
 第六节 
    1 Python中的空格是指正确的缩进
    2 练习: 改正上一节中的错误
[python]  
def spam():  
    eggs = 12  
    return eggs  
          
print spam()  
 
 第七节
    1 Python是一种解释执行的语言,只要你写完即可立即运行
    2 练习:设置变量spam的只为True,eggs的值为False 
[python] 
spam = True  
eggs = False  
 
 第八节
    1 Python的注释是通过“#”来实现的,并不影响代码的实现
    2 练习:给下面的代码加上一行注释
[python]  
#this is a comments for Python  
mysterious_variable = 42  
 
 第九节
    1 Python的多行注释是通过“ """ """  ”来实现的
    2 练习:把下面的代码加上多行
[python]  
""" 
this is a Python course 
"""  
a = 5  
 
 第十节
    1 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  
 
 
 第十一节
    1 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  
 
 

相关内容

    暂无相关文章

评论关闭