python 学习分享-基础篇

Posted

tags:

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

1、python起手式

写下第一个代码,打印‘hello world’

print(hello world)

2、变量

变量是为了存储信息,在程序中被调用,标识数据名称或类型。

变量定义的规则:

变量名只能是字母,数字或下划线的任意组合

变量名的第一个字符不能是数字

关键字不能生命为变量

为了方便读取等,变量命名一般都遵循变量本身的意义,如名字命名为name,年龄为age等等。

name = "Laay"  #字符串类型string

age = 21  #int类型

province = "shandong"

NameOfTwinsGf = "hanmeimei"

name_of_twins_gf = "hanmeimei"

address = “shanghai”

address1 = address

address = “beijing”   #address1 赋的是值,而不是变量,所以不变

3 注释

#       单行注释,最多不超过80个字符

‘‘‘ ‘‘‘   多行注释

4 格式化字符串

name = input("input your name:")
age =int( input("input your age:"))
job = input("input your job:")

print("name is :",name)
print("age is :",age)
print("job is :",job)

msg = ‘‘‘ 
infomation of user %s:
-----------------------------
name:  %s
age :  %d 
job :  %s 
-----------------------------
‘‘‘ % (name,name,age,job)
print(msg)

5 if else条件

_username = ‘Laay’
_password = ‘Laay’
username = input(input your name :)
password = input(input your password:)
if _username == username and _password == password:
    print(login..)
else:
    print(username or password is correct...)
age = 22
guess_num = int(input(input your num:))
if guess_num == age :
    print(congratulations! you got it.)
elif guess_num >age:
    print(think smaller!)
else:
    print(think bigger!)

 

6 while 循环

age = 22
counter = 0 
for i in range(10)
    if counter<3:
        guess_num = int(input(input your num:))
        if guess_num == age :
            print(congratulations! you got it.)
            break
        elif guess_num >age:        
            print(think smaller!)
        else:
           print(think bigger!)
    else:
        continue_confirm = input(Do you want to contnue because you are stupid:)
        if countinue_confirm == y
            counter   =  0
            ciontinue
        else:
            print(bye)
            break
    count + = 1

 

以上是关于python 学习分享-基础篇的主要内容,如果未能解决你的问题,请参考以下文章

[资料分享]Python视频教程(基础篇进阶篇项目篇)

零基础学习大数据人工智能,学习路线篇!

[Python从零到壹] 四十.图像处理基础篇之图像量化处理

python之基础篇——模块与包

[Python从零到壹] 三十九.图像处理基础篇之图像几何变换(镜像仿射透视)

[Python从零到壹] 三十六.图像处理基础篇之图像算术与逻辑运算详解