python初识及变量,,一、基础1、文件的后


一、基础

1、文件的后缀是 .py

2、两种执行方式

python解释器 .py文件路径

python进入解释器 实时输入并获取执行结果

3、解释器路径

#!/usr/bin/evn python (Linnux)

#-*-coding:utf8-*-

python 2中 只要出现中文,头部必须加编码(想要加头部,两行必须相邻)

python3 中无需关注

4、执行一个操作

python中 单行注释用#,多行注释用 ‘‘‘

input 的用法 永远等待 直到用户输入了值 就将输入的值赋给一个东西

5、变量只能由数字、字母、下划线组成 但不能以数字开头

python的一些关键字不能作为变量名

变量名最好有意义一些

最好不能和python内置的东西重复

user-id python中一般不用userId

6、条件语句

if 条件:

  print()#内部代码块

else:

  print()

直接用tab 代替四个空格

同一个代码块下,缩进的字符必须相等

if 支持嵌套

if、elif (类似于多条件判断)

#pass 什么都不执行 过

7、基本数据类型

数字、字符串、列表、元祖、字典、布尔值

字符串 用印号引起来 " " """ """ ‘ ‘ ‘‘‘ ‘‘‘
加法 乘法

数字 % #对一个数 取余

** 一个数的幂

判断奇偶性

temp=a%2if temp==0:    print(‘偶数‘)else:    print(‘奇数’)

使用while循环输入 123456 89

n=1 while n<=10    if n==7:        pass    else:        print(n)    n+=1print(‘end‘)

求1-100所有数的和

s=0n=1while n<101    s=s+n    n=n+1print(s)

求1-2+3-4+5 ...99的所有数的和

n=1s=0while n<100    temp=n%2    if temp==0:        s=s-n    else:        s=s+nprint(s)

输出1-100内所有奇数

n=1while n<101    temp=n%2    if temp!=0:        print(temp)    else:        pass
n=n+1

用户登录(三次重试)

count=0while  count <3       user=input(">>>")    psd=input(">>>")    if  user=="alex" ,psd=="123":        print("欢迎登陆")        break    else:        print("用户名或密码错误")    count+=1    

python初识及变量

评论关闭