Python 基础知识(1)

Python基础

一、变量

1、变量是用来存储数据对象的。


2、英文定义:

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

3、Python定义变量的规则:

  • 变量名只能是字母、数字或者下划线的任意组合。
  • 变量名的第一个字符不能是数字。
  • 以下关键字为Python关键字,不能声明为变量。
    [‘and’, ‘as’, ‘assert’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘exec’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘not’, ‘or’, ‘pass’, ‘print’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]

4、变量的赋值:

Python是动态语言,变量无需提前声明变量类型,Python变量通过赋值可以指向任意的类型or对象。


二、 字符编码(后续)


三、用户输入输出

1、列表内容

2、input()函数:

  • 在Python 3.x默认输入的都是字符串类型的数据。
>#name = raw_input("What is your name?") #only on python 2.x 
>name = input('What is your name')
>print('Hello',+name)
  • getpass函数:
    在输入密码时,如果想要密码不可见,可调用getpass模块中的getpass函数。
>import getpass
># 将用户输入的内容赋值给 name 变量
>pwd = getpass.getpass("请输入密码:")
># 打印输入的内容
>print(pwd)

五、数据类型

1、数字:

  • int(整型):在32位机器上,整数的位数为32位,取值范围为-2**31~2**31-1,即-2147483648~2147483647。
    在64位系统上,整数的位数为64位,取值范围为-2**63~2**63-1,即-9223372036854775808~9223372036854775807
  • long(长整型):自从Python2.2起,如果整数发生溢出,Python会自动将整数数据转换为长整数。
    从Python3.0开始LONG(长整型)的概念就消失了,只有整型了

  • float(浮点型):

详细介绍

  • complex(复数):
    复数由实数部分和虚数部分组成,一般形式为x+yj,其中的x是复数的实数部分,y是复数的虚数部分,这里的x和y都是实数。
    注:Python中存在小数字池:-5 ~ 257

2、布尔值

真假(1或0)


3、字符串

“”Hello World“”


  • 万恶的字符串拼接:

python中的字符串在C语言中体现为是一个字符数组,每次创建字符串时候需要在内存中开辟一块连续的空,并且一旦需要修改字符串的话,就需要再次开辟空间,万恶的+号每出现一次就会在内从中重新开辟一块空间。

六、数据运算


更多内容:猛击这里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值