马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 tommyyu 于 2020-4-11 13:12 编辑 >>> x = 3
>>> print(x)
3
·变量可以由字母、数字下划线组成,但不能由数字打头。
>>> a1 = 100
>>> a1
100
>>> 1a = 100
SyntaxError: invalid syntax
·变量名严格区分大小写
>>> 幸运数 = 588
>>> print(幸运数)
588
>>> name = '小甲鱼'
>>> print(name)
小甲鱼
>>> name = '老乌龟'
>>> print(name)
老乌龟
>>> x = 3
>>> y = 5
>>> y = x
>>> print(y)
3
>>> x = y = 3
>>> x
3
>>> y
3
>>> x = 3
>>> y = 5
>>> t = x
>>> x = y
>>> y = t
>>> print(x,y)
5 3
>>> x = 3
>>> y = 5
>>> x,y = y,x
>>> x
5
>>> y
3
"小甲鱼"和"老乌龟"用字符串扩了起来,
为什么呢?
·因为它们都是字!符!串!
·字符串
1.用单引号包裹起来
>>> print('ilovechina')
ilovechina
2.用双引号包裹起来
>>> print("ilovechina")
ilovechina
·为什么要设置两种引号呢?
·如果我们要打印Let's go,怎么办?
>>> print('Let's go!')
SyntaxError: invalid syntax
>>>print("Let's go!")
Let's go!
·小技巧:Alt + p : 上一句代码
>>> print('"life is short you need python"')
"life is short you need python"
·如果是"life is short ,let's learn Python!"怎么办??
·这时,我们就需要引入
·反!斜!杠!
>>> print('"life is short ,let's learn Python!"')
"life is short ,let's learn Python!"
·\n 是换行符。
>>> print("I love Python
I love fish.com")
I love Python
I love fish.com
Python之谭:
>>>import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
可以用py文件保存
代码如下:print(
r"""
>>> x = 3
>>> print(x)
3
·变量可以由字母、数字下划线组成,但不能由数字打头。
>>> a1 = 100
>>> a1
100
>>> 1a = 100
SyntaxError: invalid syntax
·变量名严格区分大小写
>>> 幸运数 = 588
>>> print(幸运数)
588
>>> name = '小甲鱼'
>>> print(name)
小甲鱼
>>> name = '老乌龟'
>>> print(name)
老乌龟
>>> x = 3
>>> y = 5
>>> y = x
>>> print(y)
3
>>> x = y = 3
>>> x
3
>>> y
3
>>> x = 3
>>> y = 5
>>> t = x
>>> x = y
>>> y = t
>>> print(x,y)
5 3
>>> x = 3
>>> y = 5
>>> x,y = y,x
>>> x
5
>>> y
3
"小甲鱼"和"老乌龟"用字符串扩了起来,
为什么呢?
·因为它们都是字!符!串!
·字符串
1.用单引号包裹起来
>>> print('ilovechina')
ilovechina
2.用双引号包裹起来
>>> print("ilovechina")
ilovechina
·为什么要设置两种引号呢?
·如果我们要打印Let's go,怎么办?
>>> print('Let's go!')
SyntaxError: invalid syntax
>>>print("Let's go!")
Let's go!
·小技巧:Alt + p : 上一句代码
>>> print('"life is short you need python"')
"life is short you need python"
·如果是"life is short ,let's learn Python!"怎么办??
·这时,我们就需要引入
·反!斜!杠!
>>> print('"life is short ,let\'s learn Python!"')
"life is short ,let's learn Python!"
·\n 是换行符。
>>> print("I love Python\nI love fish.com")
I love Python
I love fish.com
""")
print()
print()
print("Python之谭:\n>>>import this")
import this
|