当前位置:首页>python>Python变量 简单易懂不弯弯绕绕

Python变量 简单易懂不弯弯绕绕

  • 2026-09-08 23:26:30
Python变量 简单易懂不弯弯绕绕

变量Variable

Variable = A container for a value (string, integer, float, boolean)

A Variable behaves as if it was the value it contains

由此可见,共有四种数据类型

f-string

print(f"Hello {first_name}")print("hello " + first_name)

{value}相当于一个占位符,格式化字符串字面值

String

在python中字符串变量使用引号括起来

first_name = "bro"food = "pizza"email = "32477XXXXqq.cpm"

Integers

age = 24quantity = 3#整数数字

Flaot

price = 10.33#即浮点数(小数)

Boolean

is_student = True# oris_student = False#布尔型 只包含 错或者对,相当于C语言里面的0与非零# 一般配合条件语句if for_sale:  print("that item is for sale") #True 执行词句else:    print("that is NOT available")

Typecasting

Typecasting = the process of converting a variable from one data type to anther str(), int(), float(), bool()

即类型转换

type()

可以打印数据类型

name = "bro"print(type(name))
<class 'str'>
name = "Bro"age = 25gpa = 3.5is_student = Ture
gpa = int(gpa) # 3

最新文章

随机文章