python基础语法

python基础语法

注释的方法

  • 单行注释:#
#python
  • 多行注释:六个单引号/六个双引号
'''
python
'''

"""
python
"""
  • 注释快捷键(添加/删除注释):ctrl+/(?)

单引号和双引号的区别

无本质区别,但是在一行代码中需要多次用到单双引号的时候不能都使用单引号/双引号
eg:
正确的写法

print("姓名:'cindy'")

错误的写法:

print("姓名:"cindy"")

标识符

  • 作用:作为变量、函数、类、模块以及其他对象的名称
  • 命名规则:只能数字,字母和下划线并且不能用数字开头,并且标识符命名不能有python关键字
    python关键字:[‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’,‘async’, ‘await’, ‘break’, ‘class’, ‘continue’, ‘def’,‘del’,‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from’,‘global’, ‘if’,‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’, ‘or’,‘pass’, ‘raise’,‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]
    python关键字的查看方法:
    import keyword
    print(keyword.kwlist)
    

输入和输出

输出(print):

  • 单个输出:
print('hello python')
  • 多个输出(一般自动换行)
print('hello python')
print('hello world')

结果:

D:\python3.7\python.exe D:/Pycharm_workspace/test_cindy/app_homework/test.py
hello python
hello world

Process finished with exit code 0
  • 多个输出不换行
print('hello python',end='')
print('hello world')

结果:

D:\python3.7\python.exe D:/Pycharm_workspace/test_cindy/app_homework/test.py
hello pythonhello world

Process finished with exit code 0

输入(input):
输入的是字符串

name=input('姓名:')
age=input('年龄:')
gender=input('性别:')
print(name,age,gender)

变量

命名规则:只能数字,字母和下划线并且不能用数字开头
命名风格(常用的三种如下):

  • 全小写加下划线(单词之间加下划线)
    eg.account_name

  • 大驼峰
    eg.AccountName

  • 小驼峰
    eg.accountName

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值