Python初学4-变量与运算符

命名规则:

       1. 只能使用字母、数字、下划线。且首字母不能是数字。

        2.系统使用的关键字(保留关键字)不可以被使用。

数字
>>> A=[1,2,3]
>>> print(A)
[1, 2, 3]
>>> B=[2,3,4,5]
>>> print(A*3+B)
[1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3, 4, 5]
>>> A*3+B
[1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3, 4, 5]
字符
>>> a='java '
>>> b = 'python'
>>> a+b
'java python'
>>> c = a+b
>>> print(c)
java python
>>> c[0]
'j'
>>> c[0:5]
'java '
>>> c[0]='J'

Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    c[0]='J'
TypeError: 'str' object does not support item assignment
>>> 
>>> a=[1,2,3]
>>> print(a[1])
2
>>> a[1]=4
>>> print(a)
[1, 4, 3]
>>> a.append(6)
>>> print(a)
[1, 4, 3, 6]
>>> b=(1,2,3)
>>> b.append(5)
Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    b.append(5)
AttributeError: 'tuple' object has no attribute 'append'






猜你喜欢

转载自blog.csdn.net/qq_34819372/article/details/80632543