zoukankan      html  css  js  c++  java
  • Python变量定义

    python的输出语句

    1.支持双引号、单引号、三引号

    print("hello world")
    print('hello python')
    print("""Linux
    windows
    MacOS""")
    print('''Nginx
    Httpd
    Tomcat''')
    print("This is 'python'demo!!!") # 外面双引号,里面单引号
    print("python自动化运维")
    

    2.输出变量的值

    username="Joke"
    print(username)
    print("hello",username)
    

    3.格式化输出

    (1.)%s 字符串格式化输出

    username = "Joke"
    age = 30
    print("hello %s" % username)
    print("My name is %s,My age is %s" %(username,age))
    

    (2.)%d 整数格式化输出

    print("Thist number is %d" % 20)
    print("This number is %d" % 3.14)  # 输出为3
    

    (3.) %f 浮点数格式化输出

    print("The number is %f" % 10)
    print("The number is %f" % 3.14)
    print("The number is %.3f" % 3.1415926)  # %.3f 表示保留几位数据
    

    (4.)输出%本身

    number = 50
    print("This is %d%%" % number) # %%会输出%
    

    4.变量定义

    格式: 变量名称 = 变量值

    变量名规范

    1. 只能包含字母、数字、下划线
    2. 只能以字母或者下划线开头
    3. 见名知义
    4. 不能用python关键字,os,shutil,for,int,str

    调用变量:直接通过变量名进行变量的值

    username = "Jone"
    
    print(username)
    

    变量特性:

    (1.)弱类型变量定义

    (2.)地址引用类型

    number1=100
    print(id(number1))  # 使用id()获取变量内存地址
    ------------------------------------------
    # 变量替换
    a = 10 
    b = 20
    a,b = b,a
    print(a,b)  # 20,10
    

    5.交互式变量定义

    变量名 = input("提示信息")

    注意:intput()默认返回的数据类型为字符串

    name = input("请输入用户名:")
    print("hello %s" % name)
    ------------------------------
    data = input("数据>>>")
    print(data)
    print(type(data))  # 输出str,使用type()可以查看变量类型
    
  • 相关阅读:
    北京南天软件java工程师面试题
    祝福自己
    致青春——IT之路
    PL/SQL devloper 常用设置
    CENTOS LINUX查询内存大小、频率
    centOS安装openoffice
    echo > 和 echo >>的区别
    sqoop job 增量导入
    sqoop job从创建到执行
    sqoop导入增量数据
  • 原文地址:https://www.cnblogs.com/tomtellyou/p/15418698.html
Copyright © 2011-2022 走看看