python基础(1)--input print if else elif while 用法说明
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 用法说明的更多相关文章
- python基础_格式化输出(%用法和format用法)(转载)
python基础_格式化输出(%用法和format用法) 目录 %用法 format用法 %用法 1.整数的输出 %o -- oct 八进制%d -- dec 十进制%x -- hex 十六进制 &g ...
- 二、Python基础(input、变量名、条件语句、循环语句、注释)
一.input用法 input在Python中的含义为永远等待,直到用户输入了值,从而将所输入的值赋值另外的一个东西. n=input('请输入......') 接下来用一个例子学习input的用法 ...
- python学习-4 python基础-2 条件语句(if的简单用法1)
条件语句的原理: 2.举个例子:比大小 #!/usr/bin/env python # -*- coding:utf8 -*- a=input("请输入a:") b=input(& ...
- Python基础(条件判断和循环) if elif else for while break continue;
条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= ...
- python基础知识input到while循环
j周笔记 输入与输出 1.输入 input ('请输入内容')= 字符串 2.输出 print(输出到控制台) 变量vairable 变量就是相当于我们人的名字 1.名字 ...
- python中的input,print
此用例在python3.3.5中测试通过: 输入:在python中输入是使用input,下面示例代码表示把输入的值存入变量s中,并输入s 在这里提醒一下:使用input获取的值都是string类型
- python基础4 input()函数
input()函数 赋值输出: name=input('请求输入你喜欢的电影名:')print(name+'是我最喜欢的电影!') 输入:大话西游 输出:大话西游是我最喜欢的电影! print('那么 ...
- python基础入门--input标签、变量、数字类型、列表、字符串、字典、索引值、bool值、占位符格式输出
# 在python3 中: # nian=input('>>:') #请输入什么类型的值,都成字符串类型# print(type(nian)) # a = 2**64# print(typ ...
- Python基础语法之“print()”函数
print()函数是Python入门的第一个必学知识点,它经常被用来调试已写的代码,检验效果,今天小老鼠就带你盘点一下print()函数在Python中如何使用. print()函数的工作流程是这样的 ...
随机推荐
- Jquery对象和dom对象获取html的方法
1)DOM对象 var domObj = document.getElementById("id"); //DOM对象 domObj.innerHTML;// domObj.out ...
- TOP计划猿10最佳实践文章
本文转自:EETproject教师专辑 http://forum.eet-cn.com/FORUM_POST_10011_1200263220_0.HTM?click_from=8800111934, ...
- WPF 四种尺寸单位
原文:WPF 四种尺寸单位 像素 px 默认单位可以省略 厘米cm 英寸 in 点 pt 1in = 96px 1cm=96/2.42px 1pt=96/72px
- WPF 遍历DataTemplate(获取所有控件)
原文:WPF 遍历DataTemplate(获取所有控件) 情况1:在设定DataTemplate的Name,并且他是在前台表示时,获取DataTemplate里的指定控件. 方法: http://b ...
- WPF中的资源(一) - 静态资源和动态资源
原文:WPF中的资源(一) - 静态资源和动态资源 WPF中,每个界面元素都含有一个名为Resources的属性,其存储的是以"键-值"对形式存在的资源,而其子级元素在使用这些资源 ...
- [原译]实现IEnumerable接口&理解yield关键字
原文:[原译]实现IEnumerable接口&理解yield关键字 著作权声明:本文由http://leaver.me 翻译,欢迎转载分享.请尊重作者劳动,转载时保留该声明和作者博客链接,谢谢 ...
- Simple BeamSearch Codes for Python
Code from: https://github.com/SeitaroShinagawa/simple_beamsearch probs = [[[],[0.3,0.7]], [[0],[0.1, ...
- 零元学Expression Blend 4 - Chapter 45 ListBox里的物件不能换行吗?
原文:零元学Expression Blend 4 - Chapter 45 ListBox里的物件不能换行吗? ListBox里的排列不是垂直就是水平,觉得这样的排列很枯燥乏味吗? 想要它变聪明吗? ...
- Android零基础入门第7节:搞定Android模拟器,开启甜蜜之旅
原文:Android零基础入门第7节:搞定Android模拟器,开启甜蜜之旅 在前几期中总结分享了Android的前世今生.Android 系统架构和应用组件那些事.带你一起来聊一聊Android开发 ...
- ORACLE 11.2.0.4 安装在 rhel6 上
. 修改host文件,添加本机的host记录 [root@RACDG ~]# vi /etc/hosts 127.0.0.1 localhost localhost.localdomain local ...