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

本教程为Python初学者提供了一个友好的入门指南,介绍了Python的基本概念,包括语法特性、变量使用、数据类型、算术运算符等核心内容。教程还包含了丰富的实践练习,帮助读者快速掌握Python编程。


1 第一节

1 Python介绍

1 Python是一个高效的语言,读和写的操作都是很简单的,就像普通的英语一样

2 Python是一个解释执行的语言,我们不需要去编译,我们只要写出代码即可运行

3 Python是一个面向对象的语言,在Python里面一切皆对象

4 Python是一门很有趣的语言

2 第二节

1 变量:一个变量就是一个单词,只有一个单一的值

2 练习:设置一个变量my_variable,值设置为10

    #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

    #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

   #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 练习: 查看以下代码的错误

   def spam():
   eggs = 12
   return eggs 
   print spam()

第六节

1 Python中的空格是指正确的缩进

2 练习: 改正上一节中的错误

def spam():
    eggs = 12
    return eggs
        
print spam()

第七节

1 Python是一种解释执行的语言,只要你写完即可立即运行

2 练习:设置变量spam的只为True,eggs的值为False

   spam = True
   eggs = False

第八节

1 Python的注释是通过“#”来实现的,并不影响代码的实现

2 练习:给下面的代码加上一行注释

   #this is a comments for Python
   mysterious_variable = 42

第九节

1 Python的多行注释是通过“ """ """ ”来实现的

2 练习:把下面的代码加上多行

   """
   this is a Python course
   """
   a = 5

第十节

1 Python有6种算术运算符+,-,*,/,**(幂),%

2 练习:把变量count_to设置为1+2

     #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

   #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的平方

    #this is a Python
    monty = True
    python = 1.234
    monty_python = python**2




评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值