鱼C论坛

 找回密码
 立即注册
查看: 1295|回复: 2

[技术交流] 新版Python第三课学习笔记

[复制链接]
发表于 2020-4-11 11:59:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-4-11 12:13:46 | 显示全部楼层
建议发代码格式,上面的“<>”
效果就是这样

可读性更高哦~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-4-11 12:26:47 | 显示全部楼层
liuzhengyuan 发表于 2020-4-11 12:13
建议发代码格式,上面的“”

谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-26 08:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表