鱼C论坛

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

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

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

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

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

x
本帖最后由 tommyyu 于 2020-4-11 13:12 编辑
  1. >>> x = 3
  2. >>> print(x)
  3. 3
  4. ·变量可以由字母、数字下划线组成,但不能由数字打头。
  5. >>> a1 = 100
  6. >>> a1
  7. 100
  8. >>> 1a = 100
  9. SyntaxError: invalid syntax
  10. ·变量名严格区分大小写
  11. >>> 幸运数 = 588
  12. >>> print(幸运数)
  13. 588
  14. >>> name = '小甲鱼'
  15. >>> print(name)
  16. 小甲鱼
  17. >>> name = '老乌龟'
  18. >>> print(name)
  19. 老乌龟
  20. >>> x = 3
  21. >>> y = 5
  22. >>> y = x
  23. >>> print(y)
  24. 3
  25. >>> x = y = 3
  26. >>> x
  27. 3
  28. >>> y
  29. 3
  30. >>> x = 3
  31. >>> y = 5
  32. >>> t = x
  33. >>> x = y
  34. >>> y = t
  35. >>> print(x,y)
  36. 5 3
  37. >>> x = 3
  38. >>> y = 5
  39. >>> x,y = y,x
  40. >>> x
  41. 5
  42. >>> y
  43. 3
  44. "小甲鱼"和"老乌龟"用字符串扩了起来,
  45. 为什么呢?
  46. ·因为它们都是字!符!串!
  47. ·字符串
  48. 1.用单引号包裹起来
  49. >>> print('ilovechina')
  50. ilovechina
  51. 2.用双引号包裹起来
  52. >>> print("ilovechina")
  53. ilovechina
  54. ·为什么要设置两种引号呢?
  55. ·如果我们要打印Let's go,怎么办?
  56. >>> print('Let's go!')
  57.           
  58. SyntaxError: invalid syntax
  59. >>>print("Let's go!")
  60.           
  61. Let's go!
  62. ·小技巧:Alt + p : 上一句代码
  63. >>> print('"life is short you need python"')
  64. "life is short you need python"
  65. ·如果是"life is short ,let's learn Python!"怎么办??
  66. ·这时,我们就需要引入
  67. ·反!斜!杠!
  68. >>> print('"life is short ,let's learn Python!"')
  69. "life is short ,let's learn Python!"
  70. ·\n 是换行符。
  71. >>> print("I love Python
  72. I love fish.com")
  73. I love Python
  74. I love fish.com



  75. Python之谭:
  76. >>>import this
  77. The Zen of Python, by Tim Peters

  78. Beautiful is better than ugly.
  79. Explicit is better than implicit.
  80. Simple is better than complex.
  81. Complex is better than complicated.
  82. Flat is better than nested.
  83. Sparse is better than dense.
  84. Readability counts.
  85. Special cases aren't special enough to break the rules.
  86. Although practicality beats purity.
  87. Errors should never pass silently.
  88. Unless explicitly silenced.
  89. In the face of ambiguity, refuse the temptation to guess.
  90. There should be one-- and preferably only one --obvious way to do it.
  91. Although that way may not be obvious at first unless you're Dutch.
  92. Now is better than never.
  93. Although never is often better than *right* now.
  94. If the implementation is hard to explain, it's a bad idea.
  95. If the implementation is easy to explain, it may be a good idea.
  96. Namespaces are one honking great idea -- let's do more of those!
复制代码

可以用py文件保存
代码如下:
  1. print(
  2. r"""
  3. >>> x = 3
  4. >>> print(x)
  5. 3
  6. ·变量可以由字母、数字下划线组成,但不能由数字打头。
  7. >>> a1 = 100
  8. >>> a1
  9. 100
  10. >>> 1a = 100
  11. SyntaxError: invalid syntax
  12. ·变量名严格区分大小写
  13. >>> 幸运数 = 588
  14. >>> print(幸运数)
  15. 588
  16. >>> name = '小甲鱼'
  17. >>> print(name)
  18. 小甲鱼
  19. >>> name = '老乌龟'
  20. >>> print(name)
  21. 老乌龟
  22. >>> x = 3
  23. >>> y = 5
  24. >>> y = x
  25. >>> print(y)
  26. 3
  27. >>> x = y = 3
  28. >>> x
  29. 3
  30. >>> y
  31. 3
  32. >>> x = 3
  33. >>> y = 5
  34. >>> t = x
  35. >>> x = y
  36. >>> y = t
  37. >>> print(x,y)
  38. 5 3
  39. >>> x = 3
  40. >>> y = 5
  41. >>> x,y = y,x
  42. >>> x
  43. 5
  44. >>> y
  45. 3
  46. "小甲鱼"和"老乌龟"用字符串扩了起来,
  47. 为什么呢?
  48. ·因为它们都是字!符!串!
  49. ·字符串
  50. 1.用单引号包裹起来
  51. >>> print('ilovechina')
  52. ilovechina
  53. 2.用双引号包裹起来
  54. >>> print("ilovechina")
  55. ilovechina
  56. ·为什么要设置两种引号呢?
  57. ·如果我们要打印Let's go,怎么办?
  58. >>> print('Let's go!')
  59.           
  60. SyntaxError: invalid syntax
  61. >>>print("Let's go!")
  62.           
  63. Let's go!
  64. ·小技巧:Alt + p : 上一句代码
  65. >>> print('"life is short you need python"')
  66. "life is short you need python"
  67. ·如果是"life is short ,let's learn Python!"怎么办??
  68. ·这时,我们就需要引入
  69. ·反!斜!杠!
  70. >>> print('"life is short ,let\'s learn Python!"')
  71. "life is short ,let's learn Python!"
  72. ·\n 是换行符。
  73. >>> print("I love Python\nI love fish.com")
  74. I love Python
  75. I love fish.com
  76. """)
  77. print()
  78. print()
  79. print("Python之谭:\n>>>import this")
  80. import this
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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


可读性更高哦~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

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

谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-12 20:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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