zoukankan      html  css  js  c++  java
  • 【python3的学习之路一】输入和输出

    标识符

    • 第一个字符必须是字母或下划线
    • 标识符的其他的部分由字母、数字和下划线组成
    • 标识符对大小写敏感

    Python保留字

    即关键字,不能把它们用作任何标识符名称

    >>> import keyword
    >>> keyword.kwlist
    ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

    多行语句

    Python通常一行写完一条语句,但如果语句过长,我们可以使用反斜杠来实现多行语句

    total = 'item_one' + 
        'item_two' + 
        'item_three'

    同一行显示多条语句

    Python可以在同一行中使用多条语句,语句之间使用分号(;)分割

    total = 'item_one' + 
        'item_two' + 
        'item_three';print(total)

    输出

    用 print() 在括号中加上字符串,就可以向屏幕输入指定的文字。同时print()函数也可以接受多个字符串,采用逗号隔开的方式就可以连成一串输出(遇到逗号会输出一个空格)。

    print('Hello world!')
    print('Hi,', 'what is your name?', 'Bye!')

    关键字end可以用于将结果输出到同一行,或者在输出的末尾添加不同的字符

    print(str, end = ',')
    print(str, end = ' ')

    输入

    input()函数可以让用户输入字符串,并存放到一个变量里。

    name = input()
    age = input('How old are you?')
    print(name, 'is', age, 'years old!')
  • 相关阅读:
    linux下socket编程-TCP
    python正则表达式练习篇2
    python正则表达式练习篇
    python正则表达式基础篇
    Jmeter应用初步介绍
    数据库清除重复数据
    Nginx 获取真实 IP 方案
    Mac 实用工具bash-comletion介绍安装
    MySQL的binlog数据如何查看
    Mybatlis SQL 注入与防范
  • 原文地址:https://www.cnblogs.com/CSgarcia/p/9705759.html
Copyright © 2011-2022 走看看