#!/usr/bin/python
# -*- coding: utf-8 -*-
# Filename dataType.py
# Python有四种类型的数
# 1.整型
a = 2
print a
# 2.长整型
b = 123456789
print b
# 3.浮点数
c = 3.2E2
print c
# 4.复数 复数为实数的推广,它使任一多项式都有根。复数当中有个“虚数单位”j,它是-1的一个平方根。任一复数都可表达为x+yj,其中x及y皆为实数,分别称为复数之“实部”和“虚部”。
d = (2+3j)
print d
# 字符串,单双引号是一个意思
e = 'hello world'
print e
f = "hello world"
print f
# 三引号引用多行字符串
g = '''My name is
python'''
print g
# 转义符
h = 'what\'s your name?'
print h
# 行末加\表示继续显示下一行,不换行
i = 'this is a ap\
ple'
print i
# 字符串链接
j = 'hello' ' world'
print j
# 使用逗号会让换行变为空格
l = 'hello'
m = 'world'
print l,
print m
- 第二行是定义字符编码为utf-8,不然不能添加中文注释。
- Python中变量名必须以字母或者下划线开始,变量名只能包括大小写字母,数字,下划线。
- 变量名是大小写敏感的,a和A不是一个变量。
- 代码执行结果:
2
123456789
320.0
(2+3j)
hello world
hello world
My name is
python
what's your name?
this is a apple
hello world
hello world