Python基础一

1、第一次学Python,那么我们就先向Python打个招呼吧!

 print("hello world")

2、注释:分为单行注释、多行注释
单行注释:会在文字前面加个#号,快捷键为ctrl + /
多行注释:可以用单引号、也可以用双引号
单引号:’’’ 你的注释 ‘’’ 双引号:""“你的注释 “””

‘’’
第一行代码,
第二行代码,

‘’’
3、input的使用:在控制台上输入数据

name = input('请输入数据:')
print(name)

输出结果:

D:\软件\python\python.exe D:/zuoye/1.py
请输入数据:11
11

Process finished with exit code 0

4、数据类型

# 整型, 整数 int
# 打印 type(), 获取数据的数据类型
print(type(5))
# 浮点数 float
print(type(1.2))
# 布尔, bool
print(type(True))
# 列表, list
print(type([1,2,3]))
# 字典,  dict
print(type({"name": "yuze"}))
# 元组, tuple
print(type((1,2,3)))
# 集合, set
print(type({1,2,3}))
# 字符串
print(type("1"))

print(type(2.0))

print(type(False))

print(type('false'))

运行结果

<class 'int'>
<class 'float'>
<class 'bool'>
<class 'list'>
<class 'dict'>
<class 'tuple'>
<class 'set'>
<class 'str'>
<class 'float'>
<class 'bool'>
<class 'str'>

数据类型的转换
int --str

t = 2
print(type(str(t)))
print(type(str(False))

运行结果:

D:\软件\python\python.exe D:/zuoye/1.py
<class 'str'>
<class 'str'>

Process finished with exit code 0

基本上所有的类型都可以转化为字符串

5、变量
变量的命名规范:只可以使用数字、字母和下划线组成(不能使用数字开头)
变量命名尽量做到见名知意(尽量不要使用拼音)

常见的命令命名表示法(风格):
1、纯小写字母,每个单词之间用下划线隔开
max_num = 199999
2、大驼峰命名法:每个单词的第一个字母大写
MaxNum = 1999999
3、小驼峰命名法:第一单词开头字母小写,后面单词第一个字母大写
maxNum = 199999

_bbx_ = 10
y8_ = 20
# 求x+y的结果

name = "小明"
age = 18
gender = "男"
x = 10
y = 20
# print(y + x)

print(name)
print(age)
print(gender)

# # 尽量不要使用拼音做遍历名字
# xingming = '小红'
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值