首页 > 代码库 > 循序渐进-python-02
循序渐进-python-02
关键字和标识符
下列的标识符是 Python3 的关键字,并且不能用于通常的标识符。关键字必须完全按照下面拼写:
>>> help() Welcome to Python 3.5‘s help utility! If this is your first time using Python, you should definitely check out the tutorial on the Internet at http://docs.python.org/3.5/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, symbols, or topics, type "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", type "modules spam". help> keywords Here is a list of the Python keywords. Enter any keyword to get more help. False def if raise None del import return True elif in try and else is while as except lambda with assert finally nonlocal yield break for not class from or continue global pass
Python 中 我们不需要为变量指定数据类型。所以你可以直接写出 num1 = 1
,这样变量 abc
就是整数类型。如果你写出 num2= 1.0
,那么变量 abc
就是浮点类型。
>>> num1=1 >>> num2=1.0 >>> name="wuxinglai" >>> print(type(num1)) <class ‘int‘> >>> print(type(num num1 num2 >>> print(type(num num1 num2 >>> print(type(num2)) <class ‘float‘> >>> print(type(name)) <class ‘str‘> >>>
通过上面的例子你应该理解了如何在 Python 中定义变量,也就是只需要输入变量名和值就行了。Python 也能操作字符串,它们用单引号或双引号括起来。
从键盘读取输入
root@zwjfdisk2016:~/file/1# vim input_age.py
#!/usr/bin/python3 #coding:utf8 number=int(input("Please Input your age:")) if number >= 18: print ("你已经是成年人 Your age is %s and You are already an adult" %number) else: print ("你是未成年 Your age is %s You are a minor" %number)
root@zwjfdisk2016:~/file/1# python3 input_age.py
Please Input your age:18
你已经是成年人 Your age is 18 and You are already an adult
root@zwjfdisk2016:~/file/1# python3 input_age.py
Please Input your age:12
你是未成年 Your age is 12 You are a minor
本文出自 “有志者,事竟成” 博客,谢绝转载!
循序渐进-python-02
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。