Python 有点意思
Python 意思 有点
2023-09-27 14:24:29 时间
基本语法
>>> width = 20
>>> height = 2 * 3
>>> width * height
120
>>> x = y = z = 0
>>> x
0
>>> y
0
>>> z
0
变量在使用前,必须定义
>>> n
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined
对浮点数支持很好
>>> 7.0 / 2
3.5
>>> 7 / 2
3
>>> hello = "This is a string\n Hello Python."
>>> print hello
This is a string
Hello Python.
>>> hello
'This is a string\n Hello Python.'
print 可以输出内容。
字符串可以由 + 操作符连接(粘到一起),可以由 * 重复。
>>> word = 'Help' + 'A'
>>> word
'HelpA'
>>> word * 5
'HelpAHelpAHelpAHelpAHelpA'
这个厉害了。
>>> word[4]
'A'
>>> word[0:2]
'He'
>>> word[2:4]
'lp'
>>> word[:2]
'He'
>>> word[2:]
'lpA'
>>> word[1:100]
'elpA'
>>> word[10:0]
''
>>> word[2:1]
''
>>> word[-1]
'A'
>>> word[-2]
'p'
>>> word[-2:]
'pA'
>>> word[:-2]
'Hel'
+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4
-5 -4 -3 -2 -1
>>> s = "hello world"
>>> len(s)
11
>>> u'Hello\u0020World !'
u'Hello World !'
转码序列 \u0020 表示在指定位置插入编码为 0x0020 的 Unicode 字符(空格)。
>>> h = u'Hello\u0020World !'
>>> print h
Hello World !
>>> h
u'Hello World !'
列表
>>> a = ['hello','world',100,20]
>>> a
['hello', 'world', 100, 20]
>>> len(a)
4
>>> a[0]
'hello'
>>> a[3]
20
>>> a[0:2] + ['python',2*2]
['hello', 'world', 'python', 4]
编程
>>> a,b = 0,1
>>> a
0
>>> b
1
>>> while b < 10:
... print b
... a,b = b,a+b
...
1
1
2
3
5
8
>>> i = 2 * 2
>>> print 'The value of i is',i
The value of i is 4
学习给我快乐,没有别的目的。
相关文章
- python各类项目模块记录
- Python error:Compressed file ended before the end-of-stream marker was reached
- 人工智能为什么用python,python是什么意思
- Python在某种场景下进行重复项寻找
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 【Python】【Flask】框架
- Python 下JSON的两种编解码方式实例解析
- python实现线性排序算法-计数排序
- 概率分布之间的距离度量以及python实现(四)
- 《Python编程快速上手——让繁琐工作自动化》——1.7 小结
- 如何在Python Plotly中使用Plotly Express绘制多折线图?
- (数据科学学习手札34)多层感知机原理详解&Python与R实现
- python是什么意思?有哪些优势
- Python与C交互之指针,一篇文章搞懂内核编程
- Python 基础 之 正则表达式re解析匹配同时获取字符串中的 单引号‘’、双引号“”内的内容
- 【python】经典题型:list列表添加元素