python基础学习
来源:互联网 发布:女生做淘宝美工累吗 编辑:程序博客网 时间:2024/06/03 22:41
hello world:
message_1 = "hello python"message_2 ="world!"num=2333 #no chinese this is zhu shi#no chinesemessage_full=message_1+" "+message_2+str(num)print(message_full.title())
list:
EDG=['meiko','scout','zet',"deft"]print(EDG)del EDG[3]print(EDG)EDG.append("mouse")print(EDG)EDG.insert(1,"clearlove")print(EDG)print(EDG[0].title())print(EDG[-1].title())message="i think "+EDG[0]+" is the best sup."print(message.title())EDG.sort()print(EDG)print(len(EDG))
for:
sups=["meiko","five","mata","ming"]for sup in sups: print(sup+" is god")print("But i think meiko is the best")for value in range(1,5): print(value)numbers=list(range(1,10,2))print(numbers)squares=[value**3 for value in range(1,11)]print(squares[0:4])
if:
car="Bmw"if car.lower() == "bmw": print("true")else: print("false")print(car=="bmw")
else if:
users=["admin","rsin","zhjf","7520"]if users: for user in users: if user=="admin": print("Hello admin,would you like to see a status report?") else: print("Hello Eric,think you for logging in again.")else: print("there is no user")
zidain:
friend ={"name":"chenqiyu","nikename":"xiaoyu","age":20,"city":"beijing"}print(friend)print("not beijing,he is in nanjing")friend["city"]="nanjing"friend["class"]=10print(friend)del friend["class"]print(friend)print(friend["name"]+"("+friend["nikename"]+")"+" in "+friend["city"]+" is "+str(friend["age"])+" years old.")print("*****************************************")for key,value in friend.items(): if key!="age": print(key+":"+value) else: print(key+":"+str(value))print("*****************************************")for key in friend.keys(): print(key)print("*****************************************")for value in friend.values(): print(value)print("*****************************************")alien_0={'color':'green','points':5}alien_1={'color':'yellow','points':10}alien_2={'color':'red','points':15}aliens=[alien_0,alien_1,alien_2]for alien in aliens: print(alien)
input:
age=input("plz input your age but not in 18~50:")age=int(age)while age>=18 and age<=50: age=input("plz input your age but not in 18~50:") age=int(age)if age<18: print("you are young")elif age>50: print("you are old")number=0while number<10: number+=1 if number%2 == 1: continue print(number)
function:
def sayhello(): """show hello""" print("hello")def toyou(name="???"): """say hello to you""" print("hello "+name)def make_shirt(cm,cha="rsin"): print("the shirt with "+cha+" is "+str(cm))def get_plus(a,b): c=a+b return cdef get_users(names): for name in names: msg="hello, "+name.title()+"!" print(msg)usernames=["hannah","ty","margot"]get_users(usernames)sayhello()name=input("plz input your name:")toyou(name)cm=input("plz input your cm:")cm=int(cm)make_shirt(cm,name)a=input("plz input a:")a=int(a)b=input("plz input b:")b=int(b)c=get_plus(a,b)print(str(c))
class:
class dog(): def __init__(self,name,age): self.name=name self.age=age def sit(self): print(self.name.title()+" is sitting now") def roll_over(self): print(self.name.title()+" is rolled now")class cutedog(dog): def __init__(self,name,age): super().__init__(name,age)my_dog=cutedog('wufan',2)print(my_dog.name.title())print(str(my_dog.age))my_dog.sit()my_dog.roll_over()
file:
with open('D:\pi_digits.txt') as file_object: contents=file_object.read() print(contents)print("*******************")with open('D:\pi_digits.txt') as file_object: for line in file_object: print(line.rstrip())print("*******************")with open("D:\pi_digits.txt") as file_object: lines=file_object.readlines()pi_string=''for line in lines: pi_string+=line.strip()print(pi_string)with open('ok.txt','a') as file_obj: file_obj.write("hello boys")
dump:
import jsonnumbers=[2,3,5,7,11,13]filename='numbers.json'with open(filename,'w') as f_obj: json.dump(numbers,f_obj)
阅读全文
0 0
- Python学习----Python基础
- Python基础学习-Django基础
- Python学习笔记-Python基础
- Python学习笔记--Python基础
- 【Python】python基础学习笔记
- 学习Python基础
- 学习Python基础
- python基础学习
- python基础学习
- Python基础学习笔记
- Python基础语法学习
- Python基础学习
- Python学习----基础篇
- Python基础学习_1
- python基础学习
- python学习--基础篇
- python基础学习
- python基础学习
- JavaScript中的数组
- 1946-计算奖金
- Presto日志中出现大量的Triggering GC to avoid Code Cache eviction bugs
- 七.gradle的构建生命周期
- Nginx与Apache的突出的优缺点比较
- python基础学习
- 简单聊天室socket.io实现
- Trie(前缀树,字典树)
- JS 实现遍历某一磁盘文件夹下目录的功能
- JS数组
- Linux进程间通信之POSIX共享内存
- 【Java并发编程实战】----- AQS(一):简介
- 关于'CALayer position contains NaN: [nan nan]'异常
- 循环结构