1 变量名的命名规则:

  由数字,字母和下划线组成,但是不能以数字开头命名变量。例如 a ,b ,c ,name ,user1 user_id 等都可作为变量名称。

  1a,2b 3cd等都不行。特别注意不能以python语法中的关键字作为变量名。常见的有“class” "and" "as" "insert " "while" "elif ""else " " del" 等。

  python中的变量不需要声明,直接使用。

2 input用法

  等待用户输入。

  括号内用双引号引起来在输入前显示的内容

>>> n=input("please input your name:")回车
please input your name:huo
>>>

3 print 用法

  输出指定信息

1 直接输出英文字符
>>> print("huo")
huo
2 直接输出中文字符
>>> print("你好")
你好
3 输出变量所指代的内容(此时不加引号)
>>> n="hello world"
>>> print(n)
hello world
>>>

4 if else 用法

  判断条件是否成立,成立则执行if 下的代码块 否则执行else

a=input("please input a:")
b=input("please input b:")
#if 条件 :回车写代码块注意代码块与 if 是相错开的
if a<b: #判断a是否小于b
print(a)#如果a小于b 则执行
else:
print(b)#否则执行else

  运行结果

please input a:2
please input b:4
2
>>>
please input a:4
please input b:2
2
>>>

if语句支持嵌套

#找出三个数中的最大一个
a=input()
b=input()
c=input()
t=""
if a<b:
t=a
a=b
b=t
if a<c:
print(c)
else:
print(a)
else:
if a<c:
print(c)
else:
print(a)

  运行结果

================== RESTART: C:/Users/Shinelon/Desktop/1.py ==================
1
3
2
3
>>>
================== RESTART: C:/Users/Shinelon/Desktop/1.py ==================
4
6
5
6

elif 类似else if

a=input()
b=input()
c=input()
t=""
if a<b:
t=a
a=b
b=t
if a<c:
t=a
a=c
c=t
elif a>b:
if a<c:
t=a
a=c
c=t
if b<c:
t=b
b=c
c=t
print(a)
print(b)
print(c)

while 用法

  循环语句

示例

name=input("please input your name:")
count=0
while count<3:
passwd=input("please input your password:")
if passwd=="":
count=3
print("登入成功!")
else:
print("登入失败")
count=count+1

运行结果

please input your name:huo
please input your password:11111
登入失败
please input your password:11111
登入失败
please input your password:11111
登入失败
>>>
================== RESTART: C:/Users/Shinelon/Desktop/1.py ==================
please input your name:huo
please input your password:393407505
登入成功!
>>>

总结:   多练习 想法更重要!

python基础(1)--input print if else elif while 用法说明的更多相关文章

  1. python基础_格式化输出(%用法和format用法)(转载)

    python基础_格式化输出(%用法和format用法) 目录 %用法 format用法 %用法 1.整数的输出 %o -- oct 八进制%d -- dec 十进制%x -- hex 十六进制 &g ...

  2. 二、Python基础(input、变量名、条件语句、循环语句、注释)

    一.input用法 input在Python中的含义为永远等待,直到用户输入了值,从而将所输入的值赋值另外的一个东西. n=input('请输入......') 接下来用一个例子学习input的用法 ...

  3. python学习-4 python基础-2 条件语句(if的简单用法1)

    条件语句的原理: 2.举个例子:比大小 #!/usr/bin/env python # -*- coding:utf8 -*- a=input("请输入a:") b=input(& ...

  4. Python基础(条件判断和循环) if elif else for while break continue;

    条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= ...

  5. python基础知识input到while循环

    j周笔记 输入与输出 1.输入 input ('请输入内容')= 字符串 2.输出 print(输出到控制台) 变量vairable               变量就是相当于我们人的名字 1.名字 ...

  6. python中的input,print

    此用例在python3.3.5中测试通过: 输入:在python中输入是使用input,下面示例代码表示把输入的值存入变量s中,并输入s 在这里提醒一下:使用input获取的值都是string类型

  7. python基础4 input()函数

    input()函数 赋值输出: name=input('请求输入你喜欢的电影名:')print(name+'是我最喜欢的电影!') 输入:大话西游 输出:大话西游是我最喜欢的电影! print('那么 ...

  8. python基础入门--input标签、变量、数字类型、列表、字符串、字典、索引值、bool值、占位符格式输出

    # 在python3 中: # nian=input('>>:') #请输入什么类型的值,都成字符串类型# print(type(nian)) # a = 2**64# print(typ ...

  9. Python基础语法之“print()”函数

    print()函数是Python入门的第一个必学知识点,它经常被用来调试已写的代码,检验效果,今天小老鼠就带你盘点一下print()函数在Python中如何使用. print()函数的工作流程是这样的 ...

随机推荐

  1. code first迁移(add-migration)的时候 后面信息不能有中文 中文报错 "不支持给定路径的格式。"

  2. 简明Python3教程 14.输入输出

    简介 一些情况下你不得不让程序与用户进行交互.例如,你需要从用户处得到输入然后输出计算结果.我们可以分别通过input()和print()函数做到这些. 对于输出,我们还可以使用str(string) ...

  3. golang中jwt使用

    golang 中jwt使用方式总结. 1. golang示例代码 import ( "fmt" "time" "github.com/dgrijalv ...

  4. WPF无边框拖动、全屏、缩放

    原文:WPF无边框拖动.全屏.缩放 版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/lwwl12/article/details/78059361 先看效果 ...

  5. IIS IP地址与端口

    IP地址 全部未分配,则以下所有IP对应端口都可以访问网站指定IP,则只有指定IP可以访问网站   1 端口 可以在建立网站之后继续添加端口,则所有添加的端口均可以访问   2   3

  6. WPF中TextBlock文本换行与行间距

    原文:WPF中TextBlock文本换行与行间距 换行符: C#代码中:\r\n 或  \r 或 \n XAML中: 或 注:\r 回车 (carriage return 缩写),\n 新行 (new ...

  7. 如何Update跨表修改数据

    大家都知道用Update修改单个表的使用方法,现在来看一下用update 跨表修改数据: 首先创建表 a 然后创建表b 现在要把表b的company  根据ID更新到表a 方法一: update a ...

  8. xen学习(一)

    添加镜像源 [root@xen xen]# cat /etc/yum.repos.d/xen.repo [xen] name=xenserver baseurl=http://mirrors.163. ...

  9. 项目集成dubbo

    dubbo 用户指南: http://dubbo.io/User+Guide-zh.htm 开发指南:http://dubbo.io/Developer+Guide-zh.htm#DeveloperG ...

  10. The Portable Executable File Format from Top to Bottom(每个结构体都非常清楚)

    The Portable Executable File Format from Top to Bottom Randy KathMicrosoft Developer Network Technol ...