Python--从入门到入土--类
类
创建和使用类以及根据实参来创造事例1234567891011121314class Dog: def __init__(self,name,age): self.name = name self.age = age def sit(self): print(f"{self.name} is now sitting ") def roll_over(self): print(f"{self.name} rolled over")my_dog = Dog("willie",6)print(f"my dog's name is {my_dog.name}")print(f"my dog's age is {my_dog.age}")
12my dog's name is williemy dog ...
Pyhton--从入门到入土---函数
函数
定义函数开头使用关键字def定义函数,中间添加需要定义的函数的名字,结尾部分别忘了:
123def greet_user(): print("Hello a")greet_user()
1Hello a
向函数中传递信息1234def greet_user(user_name): """表示最简单的问候""" print(f"Hello a,{user_name.title()}")greet_user('jess')
1Hello a,Jess
传递实参
1234def describe_pet(animal_type,pet_name): print(f"i have a {animal_type}") print(f"my {animal_type}'s name is {pet_name}.")descri ...
easyxor---攻防世界(内含有异或运算)
https://note.youdao.com/s/7qIJo0BL
catchcat---攻防世界
下载以后是一个
GPS数据流
https://www.gpsvisualizer.com/map_input
来着里面导入文件然后绘制,看图就好了
Python--从入门到入土--用户输入和while循环
函数input()函数input()使程序暂停运行,等待用户输入一些文本。获取用户输入后,Python将其赋给一个变量
12message=input("tell me something and i will repeat:")print(message)
实际上上面那个表达式中input里面的“”以及里面的东西不加也是可以的0_o
int()int 只能用来将input输入的数转换成数字
123456from builtins import int, printage = int(input('age='))print(age)result=bool(age >= 18)print(result)
123age=19 //19是我输入的19True
求模运算符%,不解释
while循环形式和C的差不多,但就是不用()以及:的事情
使用标签12345678910from builtins import int, printprompt = "\nabaxiba好吧其实我可以将你输入的话输出除非你输入quit\n&qu ...
Python--从入门到入土---字典
123alien_0 = {'color':'green','points':5}print(alien_0['color'])print(alien_0['points'])
12green5
这就是一个简单的字典在Python中,字典是一系列键值对。每个键都有一个值相互关联
访问字典中的值123alien_0 = {'color':'green','points':5}new_point=alien_0['points']print(f"you have killed {new_point} alien")
1you have killed 5alien
添加键值对12345alien_0 = {'color':'green','points':5& ...
Python--从入门到入土-if语句
if语句if语句跟C语言一样,Python中的if语句也是一样的,
1234567names = ['琪亚娜','芽衣','布洛妮娅','希儿','德丽莎']for name in names: if name == '琪亚娜': print(f'{name}') else: print('没有未来的未来不是我想要的未来')
上面这个句子是定义了一个names列表,然后对列表进行循环,if在这里判断是不是‘琪亚娜’,如果是,输出名字,否则则输出‘没有未来的未来不是我想要的未来’
12345琪亚娜没有未来的未来不是我想要的未来没有未来的未来不是我想要的未来没有未来的未来不是我想要的未来没有未来的未来不是我想要的未来
条件测试
123>>>name = '琪亚娜'>>>name == '芽衣'False
小小的玩一波
123ca ...
今日无事,勾栏听曲
如题,今日无事,勾栏听曲
Python--从入门到入土--操作列表
遍历整个列表for循环123people = ['ann','bee','c++','dev--c']for person in people: print(person)
1234annbeec++dev--c
需要注意的是:
Python中的for循环与C语言中的不一样,C语言中的是
for(中间是循环条件)
但Python的是for (临时变量) in (列表)
而且需要注意的是,Python每次运行循环的时候需要注意在后面添加一个:,这在C语言中是不层出现过的,C语言中,for后面不需要加任何的标点符号。
在for循环中进行更多的操作,比如说1234people = ['ann','bee','c++','dev--c']for person in people: print(f“{person.title()},you are a good man") print(f"i c ...
<^v^>整个花活<^v^>
123456a = [6,6,6]i = 100while 1: for i in range(i+1): i=i+1 print(a*6,"\n")
想法来源@一般路过小辉夜(姬)








