Python之PycharmEdu版官方入门习题全通过(一)

这里写图片描述
通过这个帖子来记录我学习及理解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的日常使用开始

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机器人梦想家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值