c语言sscanf函数的用法是什么
255
2022-10-07
Python自动化--2.Python变量
Python自动化--1.Python环境安装-linux
Python自动化--2.Python变量
Python自动化--3.Python数据类型
Python自动化--4.python类型转换
Python自动化--5. if判断语句
Python自动化--6. 写一个python程序
Python自动化--7. 函数的定义和调用
Python变量
2.1. 变量命名规则:
1.不以下划线为开头,如_user等(有特殊含义);
2.变量命名容易读懂:如user_name
3.不适用标准库中内置的模块名或者第三方的模块名称;
4.不要用python内置的关键字:
In [3]: import keywordIn [4]: keyword.kwlistOut[4]: ['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']
2.2. 如何理解python变量赋值
s = 'hello'#变量名 s 分配给 hello 这个对象
hello 这个对象会先在内存中创建出来,然后再把变量名 s 分配给 此对象。
所以python中变量赋值,应始终看 等号右边
2.3. 多元赋值
In [8]: n1, n2 =1, 2In [9]: n1Out[9]: 1In [10]: n2Out[10]: 2In [11]: n1 = 1, 2In [12]: n1Out[12]: (1, 2)
In [13]: s1, s2 = '12' #序列类型数据In [14]: s1Out[14]: '1'In [15]: s2Out[15]: '2'
In [16]: num, s = [10, 'hello'] #列表In [17]: numOut[17]: 10In [18]: sOut[18]: 'hello'
2.4. python中的判断
In [1]: n =10In [2]: n == 10 #判断n等于10Out[2]: True #条件为真,返回TrueIn [3]: n != 10 #判断n不等于10Out[3]: False #条件为假,则返回FalseIn [4]: n > 10 #大于Out[4]: FalseIn [5]: n < 10 #小于Out[5]: FalseIn [6]: n >= 10Out[6]: TrueIn [7]: n <= 10Out[7]: True
In [10]: n = input("请输入一个数字>>:")请输入一个数字>>:10In [11]: n == 10Out[11]: FalseIn [12]: nOut[12]: '10' #'10'字符串
上述判断会发现返回结果为 False
在编程语言中,数据是有类型之分的。
input() 在接受到任何数据都会成为 字符串类型(str),即普通字符串
而等号右边的 10 是整型(int)
如:In [13]: '10' == 10Out[13]: FalseIn [14]: '10' > 10---------------------------------------------------------------------------TypeError Traceback (most recent call last)
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~