Fastpython
Python 快速上手#
本章节将记录python的基本语法,通过阅读,你可以快速上手读懂简单代码。(当然gpt也是大家的好帮手)
但非常建议大家在有精力时可以体系化的学习学习这门语言
判断语句#
and 或者 or,后面用冒号,tab分层,elif
we dont have to use the exclamation point symbol!, the vertical bar|, ampersand&
bool变量(二元判断符)#
Loop循环#
counter = 0
while counter < 100:
print(counter)
counter += 1
for x in range(100):
print(x)
for x in range(0, 100, 2)
print(x)
# not include 100
Loop(redux)#
pizza = {
"cheese": 9,
"pepperoni": 10,
"vegetable": 11,
"chicken": 12
}
for pie in pizza:
print(pie)
for pie,price in pizza.items():
print(price)
print("A whole {} pizza costs ${}".format(pie,price))
print("A whole"+ pie + "pizza costs $" + str(price))
print("A whole %s pizza costs $%2d" % (pie,price)) # deprecated in python3
List列表#
Tuple元组#
Dictionary#
Function#
Object#
It's similar to c++.
class Student():
def __init__(self, name, id):
self.name = name
self.id = id
def change_ID(self, id):
self.id = id
def print(self):
print("{} - {}".format(self.name, self.id))
jane = Student("Jane", 10)
jane.print()
jane.change_ID(11)
jane.print()
Data structure#
遍历技巧的函数:items、enumerate、zip、reverse、sorted
Last update:
2024年1月28日 13:01:36
Created: 2023年8月7日 22:37:58
Created: 2023年8月7日 22:37:58