python初识

一 。python的基础

  1.编码

     # -*- coding:utf8 -*-

    意思使用utf8d进行编码 

    ascill     00000000
       &          00000001
    
       unicode    0000000000000000+
    
        &          0000000000000001
        中         001000000000000111110010
    
        utf-8      能用多少表示就是用多少表示
        在utf-8中 能少就少 特别是在ascill中有的字符编码
        &          0000 0001
        中         0010 0000 0000 0001 1111 0010

    在python2中 需要用到以上语句

    在python3中 不需要

  2.python的基本输入输出语句

 

    n = input('请输入用户名:')#  默认input获取的是字符类型  
    print(n) #

   3.变量名

    字母
     数字
     下划线
 
     特例:不能用数字开头
     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

二.条件语句和基本数据类型

    1.if else语句

      

    n1 = input('请输入:')

    if n1 == 'alex':
        n2 = input('>>>')
        if n2 == '确认':
            print('alex sb')
        else :
            print('alex db')
    else:
        print('error')

 

      注意:
            n1 = "alex"   赋值
            n1 == 'alex'  比较,

 

      if或者else后面跟着的代码快最好是4个空格   if lese后面不可以为空

      而且必须空格数两都要一样  

      

    2.if elif语句

      if 条件1:
            pass
         elif 条件2:
            pass
         elif 条件3:
            pass
         else:
            pass
         print('end')

 

      pass代表空代码

     3.and  or  

        

      n1 = input('n1>>>')
      n2 = input('n2>>>')
      if n1 == 'alex' and n2 == '123':
       print('OK')
      else:
        print('no')

      and:代表两个条件都需要成立

      or:代表只有一个条件成立即可

    4.数据类型字符串

     引号引起来的都是字符串

      

name = "alex"
name1 = '1234'
name2 = """5678"""
name3 = '''9999'''
# 加法
n3 = name1 + name2
    
# 乘法    
n4 = name2 * 10        

 

    4.数据类型数字

     数字:

      a1 = 10

      a2 = 20

          a3 = 4**4

      a3 = 39 % 8   取余

      a3 = 39 // 8    取商

三.while循环

    

cx = 0
while cx < 10:
    print('ok')
    cx = cx+1
print('123')

    

 while 条件:
      pass
 else:
      print("123")

      continue:结束本次循环   回到循环的开头

       break:结束整个循环   执行循环后面的代码

    while后面的代码块和if后面的一样  4个空格和而且空格数量需要一样

 四.运算符

  1.基本运算符

    +  -  *  /  %  //  **  =

   2.成员运算符

     in

     ont in

      

name = '于泽洋'
if '' in '于泽洋':
    print('ko')
else :
    print('no')

    

     查看是否属于子字符串   not in  和 in相反

  3.逻辑元算符

    and  or 

    and 的优先级大于 or的优先级

    

user = 'alex'
pwd = '123'
v = user == 'alex' and pwd == '123' and pwd == '2123' or 2 == 1
print(v)

 

转载于:https://www.cnblogs.com/yzy886886/p/9108053.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值