首页 技术 正文
技术 2022年11月15日
0 收藏 857 点赞 5,051 浏览 2374 个字

Print(“hello word!”)#打印hello word!向python世界发生第一声呐喊,仪式很重要

定义变量

name=”Alex Li”

name2=name

print(“my name is “,name,name2)

输出结果:my name is Alex Li Alex Li

name=”paoche ge”

print(name,name2)

输出结果: paoche ge Alex Li   #nam2通过name找到Alex的内存地址,name重新赋值,会开辟另一个内存地址存paoche ge,name2还是alex

变量赋值不能有空格,第一个字符必须是(字母或_,可有字母,_和数字组成,大小写敏感)

PIE=3.1415296   #可以用大写字母表示常量

input

1 name=input("name:")2 age=int(input("age:")) #interger3 job=input("job:")4 salary=input("salary:")

格式输出

  1 info=""""------info of {_name}-----  2 Name={_name}  3 Age={_age}  4 Job={_job}  5 Salary={_salary}  6 ---------end-------"""  7 .format(_name=name,  8                  _age=age,  9                  _job=job, 10                  _salary=salary) 11 print(info) 12 13 info2= 14 """------info of %s----- 15 Name=%s 16 Age=%d 17 Job=%s 18 Salary=%S 19 ---------end-------"""%(name,name,age,job,salary) 20 Print(info2) 21 22 info3 = 23 =""""------info of {0}----- 24 Name={0} 25 Age={1} 26 Job={2} 27 Salary={3} 28 ---------end-------""".fomat(name,name,age,job,salary) 29 print(info3)

while循环

  1 age_of_oldboy=56  2 count=0  3 while count<3:                           #判断循环条件  4    guess_age = int(input("guess age:"))  # input默认读取字符串  5    if guess_age==age_of_oldboy:  6         print("yes,good!")  7         break  8    elif guess_age > age_of_oldboy:  9          print("think smaller") 10    else: 11          print("think bigger") 12    count +=1 13 if count==3: 14     print("fuck off") """也可以不用elif age_of_oldboy=56 count=0 while count<3:                           #判断循环条件    guess_age = int(input("guess age:"))  # input默认读取字符串    if guess_age==age_of_oldboy:         print("yes,good!")         break    if guess_age > age_of_oldboy:          print("think smaller")    if guess_age < age_of_oldboy:          print("think bigger")    count +=1 else:     print("fuck off") """

guess任性玩

  1 age_of_oldboy=56  2 count=0  3 while count<3:                           #判断循环条件  4    guess_age = int(input("guess age:"))  # input默认读取字符串  5    if guess_age==age_of_oldboy:  6         print("yes,good!")  7         break  8    elif guess_age > age_of_oldboy:  9          print("think smaller") 10    else: 11          print("think bigger") 12    count +=1 13    if count==3: 14        print("are you want to try again?") 15        continue_result=input("") 16        if continue_result==("no")or continue_result==("n"): 17            count==4 18        else: 19            count=0

for循环

1 for i in range(10):2     print("------",i)3     for j in range(10):4         print(j)5         if j>5:6             break            #跳出当前整个循环//continue 是跳出本次循环继续下次循环

for循环之猜年龄

 1 age_of_oldboy=56 2 i=0 3 for i in range (3):                           #判断循环条件 4    guess_age = int(input("guess age:"))  # input默认读取字符串 5    if guess_age==age_of_oldboy: 6         print("yes,good!") 7         break 8    elif guess_age > age_of_oldboy: 9          print("think smaller")10    else:11          print("think bigger")12    i+=113 if i==3:14          print("fuck off")1516 for i in range(0,10,3):   #从0开始到10结束,每隔三个打印一个17 print("loop",i)18 for i in range(10):19     print("------",i)20     for j in range(10):21         print(j)22         if j>5:23             break  #跳出当前整个循环//continue 是跳出本次循环继续下次循环
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905