零基础学习pythonTask02

参考资料:https://linklearner.com/datawhale-homepage/index.html#/learn/detail/6

数学运算、字符串和文本列表

实现第一行代码和认识注释

#认识注释,注释是由# 加相关备注,但是不会在代码中运行,可以作为帮助理解的功能
#写出你的第一行代码向世界问好
print('hello world!')
hello world!

数学运算

#认识运算符
#加减乘除等以及特殊符号
#• + plus,加号
#• - minus,减号
#• / slash,斜杠
#• * asterisk,星号
#• % percent,百分号
#• < less-than,小于号
#• > greater-than,大于号
#• <= less-than-equal,小于等于号
#• >= greater-than-equal,大于等于号

print("I will now count my chickens:")
print("Hens", 25 + 30 / 6)
print("Roosters", 100 - 25 * 3 % 4)
print("Now I will count the eggs:")
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
print("Is it true that 3 + 2 < 5 - 7?")
print(3 + 2 < 5 - 7)
print("What is 3 + 2?", 3 + 2)
print("What is 5 - 7?", 5 - 7)
print("Oh, that's why it's False.")
print("How about some more.")
print("Is it greater?", 5 > -2)
print("Is it greater or equal?", 5 >= -2)
print("Is it less or equal?", 5 <= -2)
I will now count my chickens:
Hens 30.0
Roosters 97
Now I will count the eggs:
6.75
Is it true that 3 + 2 < 5 - 7?
False
What is 3 + 2? 5
What is 5 - 7? -2
Oh, that's why it's False.
How about some more.
Is it greater? True
Is it greater or equal? True
Is it less or equal? False

字符串和文本

#字符串如何引用
cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven     

print("There are", cars, "cars available.")
print("There are only", drivers, "drivers available.")
print("There will be", cars_not_driven, "empty cars today.")
print("We can transport", carpool_capacity, "people today.")
print("We have", passengers, "to carpool today.")
print("We need to put about", average_passengers_per_car,"in each car.")
There are 100 cars available.
There are only 30 drivers available.
There will be 70 empty cars today.
We can transport 120.0 people today.
We have 90 to carpool today.
We need to put about 3.0 in each car.
#自己的信息引用
my_name = 'Zed A. Shaw'
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 # lbs
my_eyes = 'Blue'
my_teeth = 'White'
my_hair = 'Brown'

print(f"Let's talk about {my_name}.")
print(f"He's {my_height} inches tall.")
print(f"He's {my_weight} pounds heavy.")
print("Actually that's not too heavy.")
print(f"He's got {my_eyes} eyes and {my_hair} hair.")
print(f"His teeth are usually {my_teeth} depending on the coffee.")

# this line is tricky, try to get it exactly right
total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")
Let's talk about Zed A. Shaw.
He's 74 inches tall.
He's 180 pounds heavy.
Actually that's not too heavy.
He's got Blue eyes and Brown hair.
His teeth are usually White depending on the coffee.
If I add 35, 74, and 180 I get 289.
#输入一整段字符串、变量和格式
types_of_people = 10
x = f"There are {types_of_people} types of people."

binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."

print(x)
print(y)

print(f"I said: {x}")
print(f"I also said: '{y}'")

hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"

print(joke_evaluation.format(hilarious))

w = "This is the left side of..."
e = "a string with a right side."

print(w + e)
There are 10 types of people.
Those who know binary and those who don't.
I said: There are 10 types of people.
I also said: 'Those who know binary and those who don't.'
Isn't that joke so funny?! False
This is the left side of...a string with a right side.

列表

#List(列表) 是 Python 中使用最频繁的数据类型。
#列表可以完成大多数集合类的数据结构实现。它支持字符,数字,字符串甚至可以包含列表(即嵌套)。
#列表用 [ ] 标识,是 python 最通用的复合数据类型。
#列表中值的切割也可以用到变量 [头下标:尾下标] ,就可以截取相应的列表,从左到右索引默认 0 开始,从右到左索引默认 -1 开始,下标可以为空表示取到头或尾。
list = [ 'runoob', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
 
print(list)                # 输出完整列表
print(list[0])            # 输出列表的第一个元素
print(list[1:3])           # 输出第二个至第三个元素 
print(list[2:])            # 输出从第三个开始至列表末尾的所有元素
print(tinylist * 2)        # 输出列表两次
print(list + tinylist)     # 打印组合的列表
['runoob', 786, 2.23, 'john', 70.2]
runoob
[786, 2.23]
[2.23, 'john', 70.2]
[123, 'john', 123, 'john']
['runoob', 786, 2.23, 'john', 70.2, 123, 'john']
如果你是零基础学习Python,我建议你从基础语法开始学习。你可以先了解变量和常量的概念,学习如何使用注释来提高代码的可读性。此外,了解Python的垃圾回收机制也是很重要的。\[1\] 一旦你掌握了基础语法,你可以学习Python的基本数据类型,如字符串、整数、浮点数等。学习如何与用户进行交互,并学习如何格式化输出。此外,你还可以了解Python的基本运算符,如加法、减法、乘法等。\[1\] 在掌握了基础语法和基本数据类型后,你可以学习流程控制,如if判断语句、while循环和for循环。这些语句可以帮助你根据条件执行不同的代码块或重复执行特定的代码块。\[1\] 另外,了解Python中的可变和不可变类型以及深浅copy的概念也是很重要的。这些概念可以帮助你更好地理解Python中的数据类型。\[1\] 如果你想进一步学习Python的高级特性,你可以学习函数的基本使用、函数参数、函数对象和函数嵌套等内容。了解名称空间和作用域的概念也是很重要的。此外,你还可以学习闭包函数、装饰器、迭代器和生成器等内容。\[3\] 最后,你可以学习模块的概念和如何使用模块来组织和管理代码。模块可以帮助你将代码分成不同的文件,并提供了一种方便的方式来重用代码。\[3\] 总之,对于零基础学习Python的人来说,建议从基础语法开始学习,逐步深入学习不同的概念和特性。同时,可以参考一些全面的学习资料,如提到的那份资料,它包含了Python的各个方面的知识点,适合初学者学习和查找知识点。\[2\] #### 引用[.reference_title] - *1* *2* *3* [python入门教程(非常详细),从零基础入门到精通,看完这一篇就够了](https://blog.csdn.net/Python_0011/article/details/122488652)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值