python-tutorials/tests/Variables.py

39 lines
827 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
# Python 程序的变量variables定义
# Version: 0.1
# Author: YuCheng Hu
# 创建变量和指定变量类型
x = 1 # 变量赋值定义一个变量x
print(id(x)) # 打印变量x的标识
print(x + 1) # 使用变量
x = 2 # 量赋值定义一个变量x
print(id(x)) # 此时的变量x已经是一个新的变量
print(x + 1) # 名称相同但是使用的是新的变量x
x = 4 # x 是整数类型的
x = "OSSEZ" # x 类型将会修改为字符串
print(x)
print("==================")
x = 5
y = "John"
print(x)
print(y)
# 类型转换
x1 = str(3) # x will be '3'
x2 = int(3) # y will be 3
x3 = float(3) # z will be 3.0
x4 = chr(31243) # z will be 3.0
x5 = ord('') # z will be 3.0
# 获得类型
print("==================")
x = 5
y = "John"
print(type(x))
print(type(y))