Python之PycharmEdu版官方入门习题全通过(一)
2018-01-30 20:37
381 查看
通过这个帖子来记录我学习及理解Python的过程
1 介绍
1.1 输出 hello world
print("Hello, world! My name is yourName")
从这里就开始了我的第一行Python代码
1.2 在代码中写注释
# This is the comment for the comments.py file print("Hello!") # this comment is for the second line 这一行是注释 print("# this is not a comment") #但是"#"写到输出里就会输出出来而不是注释了 # add new comment here
2 变量
2.1 变量的定义
a = b = 2 # This is called a "chained assignment". It assigns the value 2 to variables "a" and "b". #同时定义两个变量 print("a = " + str(a)) # We'll explain the expression str(a) later in the course. For now it is used to convert the variable "a" to a string. print("b = " + str(b)) greetings = "greetings" print("greetings = " + str(greetings)) greetings = "WTF" print("greetings = " + str(greetings))
2.2 未定义变量
variable = 1 print(sstd) #NameError: name 'sstd' is not defined #变量未定义
2.3 变量类型
number = 9 print(type(number)) # print type of variable "number" float_number = 9.0 print(type(float_number)) #Out Put #<class 'int'> #<class 'float'>
2.4 类型转换
number = 9 print(type(number)) # print type of variable "number" float_number = 9.0 print(float_number) print(int(float_number)) #将float型变量转换为int型
2.5 运算符
number = 9.0 # float number result = number /2 #除法 remainder = number%2 #求余数 print("result = " + str(result)) print("remainder = " + str(remainder)) #Out Put #result = 4.5 #remainder = 1.0
2.6 自运算
number = 9.0 print("number = " + str(number)) number -= 2 print("number = " + str(number)) number += 5 print("number = " + str(number)) #Out Put #number = 9.0 #number = 7.0 #number = 12.0
2.7 布尔型操作
two = 2 three = 3 is_equal = two == three print(is_equal) #Out Put #False
2.8 比较运算符
one = 1 two = 2 three = 3 print(one < two < three) # This chained comparison means that the (one < two) and (two < three) comparisons are performed at the same time. is_greater = three > two print(is_greater) #True one<two & two<three 同时成立 #True thre>two 成立
证明上述结论的另一个例子
one = 1 two = 3 three = 2 print(one < two < three) # This chained comparison means that the (one < two) and (two < three) comparisons are performed at the same time. is_greater = three > two print(is_greater) #Out Put #False #False
下一章从string的日常使用开始
相关文章推荐
- 通过angularJS官方案例快速入门
- Python从入门到实践 习题15-6
- Python 从入门到实践 6-7 课后习题
- 零基础入门学习Python习题1【爱因斯坦台阶+猜数字】
- python从入门到实践 第八章习题(高级编程技术 week4-2)
- Python入门的36个例子 之 21 -> Dictionary —— 通过你的ID找到你
- Python 从入门到实践 5-3 课后习题
- 【鱼C·零基础入门学习Python】课后习题答案 第14课
- Python 官方文档:入门教程
- zerorpc-python官方入门
- 使用Pyenv通过国内镜像下载Python(绕过官方下载地址)
- Python 从入门到实践 8-3 课后习题
- 机器学习00:如何通过Python入门机器学习
- python下requests的安装、测试、入门资料、官方资料
- python 从入门到实践 第五章习题 (高级编程技巧 week3-1)
- python 从入门到实践第四章习题 (高级编程技术 week2-2)
- python从入门到实践 第七章习题 (高级编程技术 week4-1)
- 【鱼C·零基础入门学习python】第16课到第22课习题答案
- python从入门到实践 第十章习题(高级编程技术 week5-2)
- Coursera 零基础Python入门系列课程习题解答