0_通用

地址: 练习 13 参数,解包,变量 - 《笨办法学Python3(Learn Python3 The Hard Way 中文版)》 - 书栈网 · BookStack

1.0 变量和赋值

a1 = 123    # Int
a2Float = 12.30    #Float
b1_str = 'abc'    #string
c1 = f"There are {a1} types of people."    # {} 是变量, " "中输出参数值需要加f, 即format 格式化后放入

#多行字符串用"""  """或''' '''
fat_cat = """ 
 I'll do a list:
\t* Cat food
 \t* Fishies
 \t* Catnip\n\t* Grass
"""

附、常用格式:

Code C 类型 Python 类型 最小字节
'b' signed char int 1
'B' unsigned char int 1
'u' Py_UNICODE Unicode 2
'h' signed short int 2
'H' unsigned short int 2
'i' signed int int 2
'I' unsigned int int 2
'l' signed long int 4
'L' unsigned long int 4
'f' float float 4
'd' double float 8

1.1 输入 & 输出

print(a1)
print("a1=", a1)

hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"
print(joke_evaluation.format(hilarious))  #  .format 格式化后放入

print("How old are you?", end=' ')  # 'end=' 不另起一行
age =input()
print(f"So, you're {age} old")

1.2 数组和遍历

Python 数组 - 菜鸟教程

a3 = [1, 3.5, "Hello"]

import array as arr
a = arr.array('d', [1.1, 3.5, 4.5])    # array模块需要同类型
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容