python学习第一周

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python学习第一周相关的知识,希望对你有一定的参考价值。

一、python简单使用

1、简单程序编写
print("Hello World!")
name = "Laogui Lv"
print("My name is",name)
完成第一个程序,hello world以示正式进入python学习

2、变量赋值及变量输出
‘‘‘ ‘‘‘内代码可以换行
单行代码注释:#
多行代码注释:采用三个单引号或者三个双引号,要成套出现
# -*- coding:utf-8 -*- 
# Author:Laogui Lv
name = input("name:")
age = int(input("age:"))
print(type(age),type(str(age)))
job = input("job:")
salary = input("salary:")

"""
name = input("name:")
age = input("age:")
job = input("job:")
salary = input("salary:")

info = ‘‘‘
------info of ‘‘‘ + name + ‘‘‘ -----
Name:‘‘‘ + name + ‘‘‘
Age:‘‘‘ + age + ‘‘‘
Job‘‘‘ + job + ‘‘‘
Salary:‘‘‘ + salary + ‘‘‘
‘‘‘
"""
#info是第一种格式输出

info2 = ‘‘‘
------info of %s -----
Name:%s
Age:%s
Job:%s
Salary:%s
‘‘‘ % (name,name,age,job,salary)
#info2是第二种格式输出

info3 = ‘‘‘
------info of %s -----
Name:%s
Age:%d
Job:%s
Salary:%s
‘‘‘ % (name,name,age,job,salary)
#info3是第三种格式输出

info4 = ‘‘‘ ------info of {0} -----
Name:{0}
Age:{1}
Job:{2}
Salary:{3}
‘‘‘.format(name,age,job,salary)
#info4是第四种格式输出

info5 = ‘‘‘
------info of {_name} -----
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
‘‘‘.format(_name=name,_age=age,_job=job,_salary=salary)
#info5是第五种格式输出

print(info5)
3、if-else判断语句、while循环
# -*- coding:utf-8 -*- 
# Author:Laogui Lv
guess_age = 25
count = 0
while count < 3:
_guess_age = int(input("guess_age:"))
if guess_age == _guess_age:
print("yes,You got it.")
break
elif _guess_age > guess_age:
print("Thinking is bigger...")
else:
print("Thinging is smaller...")
count = count +1
if count == 3:
cont_guess = input("Do you want to continue?")
if cont_guess != ‘n‘:
count = 0
else:
print("Game over!")

4、for循环
# Author:Laogui Lv
guess_age = 25
count = 0
for i in range(3):
_guess_age = int(input("guess_age:"))
if _guess_age == guess_age:
print("You are right!")
elif _guess_age < guess_age:
print("please input bigger...")
else:
print("please input smaller...")
else:
print("You‘re trying too many times..")
























































































以上是关于python学习第一周的主要内容,如果未能解决你的问题,请参考以下文章

第一周:Python学习笔记

python学习笔记(第一周):变量

学习python的第一步,记住这些单词,一周就能上手敲代码

Python 学习第一周

Python学习之旅--第一周--初识Python

第一周Python学习7-30