alex python of day1

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:")) #interger
3 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+=1
13 if i==3:
14          print("fuck off")
15
16 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 是跳出本次循环继续下次循环
上一篇:细述 Java垃圾回收机制→Types of Java Garbage Collectors


下一篇:网络协议 3 - 从物理层到 MAC 层