Python全栈开发,Day1 一、Python介绍及版本 二、编程语言的分类及优缺点 三、运行第一个python程序 四、变量 五、常量 六、注释 七、基础数据类型 八、用户交互 九、if及while循环的一些基本结构  习题部分

  Python崇尚优美、清晰、简单,是一个优秀并广泛使用的语言。

  目前Python主要应用领域:

    云计算:云计算最火的语言

    WEB开发:众多优秀的WEB框架,众多大型网站均为Python开发,典型WEB框架有Django

    科学运算、人工智能:典型库NumPy, SciPy, Matplotlib, Enthought librarys,pandas

    系统运维:运维人员必备语言

    金融:量化交易,金融分析

    图形GUI: PyQT, WxPython,TkInter

Python全栈开发,Day1
一、Python介绍及版本
二、编程语言的分类及优缺点
三、运行第一个python程序
四、变量
五、常量
六、注释
七、基础数据类型
八、用户交互
九、if及while循环的一些基本结构
 习题部分

二、编程语言的分类及优缺点

  解释型:当程序运行时,将代码一行一行的解释成二进制,解释一行运行一行。

    优点:快速排错,开发效率高,可跨平台

    缺点:程序运行性能相当较低

    典型:Python

  编译型:将程序代码一次性全部编译成二进制,然后再运行。

    优点:程序性能高

    缺点:排错慢,开发效率高,不能跨平台

    典型:C语言

三、运行第一个python程序

#!/usr/bin/env python
# -*- coding: utf-8 -*-

print("hello,world!")

四、变量

  1.  变量必须由数字,字母,下划线任意组合。
  2.  变量不能以数字开头。
  3.  变量不能是python中的关键字。['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda','not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
  4.     变量要具有可描述性。fdjsaf = '美女'。
  5.     变量不能是中文。
  6.     变量不能太长。
  7.     官方推荐:

        #驼峰体

          AgeOfOldboy = 56

          NumberOfStudents = 100

        #下划线

          age_of_oldboy = 56

          number_of_students = 80

五、常量

  不变的量:出生日期、身份证号等。python没有规定,默认全部大写的变量成为常量,BIRTH = 19970425

六、注释

  作用:方便自己随时记起代码的作用,以及其他人容易看懂你的代码。

  种类:

  •  单行注释:#。 例如:#被注释内容
  •     多行注释:'''被注释内容'''或"""被注释内容"""  

七、基础数据类型

   type() 判断此数据是什么数据类型。

 1.  数字类型int

    用于计算或比较。

i = 2
print(i * 3)

  2.  字符串类型str

    用于字符串(加引号就是字符串)

name = '老男孩'
name2 = '路飞学院'
print(name,'与',name2)

#'与"混合使用防止错乱
msg = "My name is jim,I'm 26 years old!"

msg = '''
   今天我想写首小诗,
   歌颂我的同桌,
   你看他那乌黑的短发,
   好像一只炸毛鸡。
'''

#字符串拼接
n1 = '你在'
n2 = '看博客'
n3 = n1 + n2
print(n3)

  3.  布尔值

    布尔值用于判断正确与否,其结果只能为True或False

print(1 > 2 and 3 < 4 or 4 > 5)

八、用户交互

  input数据类型全部是字符串类型。

    python 2x:raw_input()

    python 3x:input()

name = input("请输入你的名字:")
age = input("请输入你的年龄:")
hobby = input("请输入你的爱好:")
s = "你的名字是" + name + ",今年" + age + "岁," + "爱好" + hobby
print("我的名字是%s,我的年龄是%s,我的爱好%s" % (name,age,hobby))
print(s)

九、if及while循环的一些基本结构

  if

if 条件:
    结果
if 条件:
    结果
else:
    结果
1 choice = input('请输入你猜的数字:')    
2 if choice == '2':
3     print('')
4 elif choice == '3':
5     print('')
6 elif choice == '4':
7     print('')
1 choice = input('请输入你猜的数字:')    
2 if choice == '2':
3     print('')
4 elif choice == '3':
5     print('')
6 elif choice == '4':
7     print('')
8 else:
9     print('选择错误...')
1 if 条件:
2     if 条件:
3         结果
4     else:
5         结果
6 else:
7     结果
1 age = int(input('请猜我的年龄:'))
2 if True:
3     if age <= 18:
4         print('恭喜你猜对了!')
5     else:
6         print('这都看出来...')
7 else:
8     print(666)

  while

while 条件:
    结果
while True:
   print('青花')
   print('王妃')
   print('凉凉')
   print('深夜地下铁')
print(222)
while True:
   print(111)
   print(222)
print(444)

  跳出循环的条件:

    1、改变条件

    2、break

  break:结束循环

  continue:结束本次循环,继续下一次循环

flag = True
while flag:
	print('等一分钟')
	print('你的背包')
	print('彩色的黑')
	flag = False
flag = True
count = 1
while flag:
	print(count)
	count = count + 1
	if count == 101:
		flag = False
while True:
	print(111)
	print(222)
	break
	print(333)
count = 1
while True:
	print(count)
	count = count + 1
	if count == 101:
		break

 习题部分

1、使用while循环输入 1 2 3 4 5 6     8 9 10

count = 0
while count < 10:
	count = count + 1
	if count == 7:
		continue
	print(count,end = '  ')

 2、求1-100的所有数的和

sum = 0
count = 0
while count < 100:
	count = count + 1
	sum = sum + count
	if count != 100:
		continue
	print(sum)

 3、输出 1-100 内的所有奇数

count = 0
while count < 100:
	count = count + 1
	if count % 2 == 1:
		print(count)

 4、输出 1-100 内的所有偶数

count = 0
while count < 100:
	count = count + 1
	if count % 2 == 0:
		print(count)

 5、求1-2+3-4+5 ... 99的所有数的和

count = 0
sum1 = 0
sum2 = 0

while count < 99:
	count = count + 1
	if count % 2 == 1:
		sum1 = sum1 + count
	else:
		sum2 = sum2 + count
	print(sum1-sum2)

 6、用户登陆(三次机会重试)

username = 'jhong'
password = '123'
count =  2

while count >= 0:
	_username = input('请输入用户名:')
	_password = input('输入你的密码:')
	if username == _username and password == _password:
		print('欢迎用户' + username + '登录...')
		break
	else:
		print('你输入的用户名或密码不正确!还有' + str(count) + '次输入机会。')
	count = count - 1