zoukankan      html  css  js  c++  java
  • python之变量初探

    01

    1. 基本数据类型
      Python 中的变量不需要声明。每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。
      在 Python 中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存中对象的类型。
      等号(=)用来给变量赋值。
      等号(=)运算符左边是一个变量名,等号(=)运算符右边是存储在变量中的值。例如:
    a = 123 #整型
    b = 45.2 #浮点
    name = '李华' #字符串
    c = False # boolean
    

    多个变量赋值

    a,b,c = 1,2,3
    
    1. 字符
    name = input("请输入姓名:")
    age = input("请输入年龄:")
    height = input("请输入身高:")
    print('我叫%s'%name+',年龄%s岁'%age+',身高%sCM'%height)	
    

    请输入姓名:李明
    请输入年龄:18
    请输入身高:175.5
    我叫李明,年龄18岁,身高175.5CM

    python字符串格式化符号:

    符号 描述
    %s 格式化字符串
    %d 格式化整数
    %f 格式化浮点数

    python字符串的formit():

    "{} {}".format("hello", "world")    # 不设置指定位置,按默认顺序
    >>'hello world'
     
     "{0} {1}".format("hello", "world")  # 设置指定位置
    >>'hello world'
     
     "{1} {0} {1}".format("hello", "world")  # 设置指定位置
    >>'world hello world'
    
     "{str1} {str2}".format(str1="hello",str2= "world")  # 设置指定位置
    >>'world hello'
    
    1. 倒序输出一个数
    num = int(input("请输入三位数"))#198
    fir = num % 10
    sec = num//10%10
    thr = num // 100
    
    result = fir*100+sec*10+thr*1
    print(result)
    >>请输入三位数459
    >>954
    
    爱,就是你和某个人一起经历的一切。
  • 相关阅读:
    css颜色表示法&颜色表
    css单位
    DOM与BOM
    position定位
    grid layout
    Linux禁止Ping方法
    tracert(traceroute)与ping
    服务器负载均衡技术的原理
    Struts2与webx的比较
    SpringAOP的原理
  • 原文地址:https://www.cnblogs.com/afly-8/p/13561159.html
Copyright © 2011-2022 走看看