一、python简介
1、python的创始人为吉多·范罗苏姆(Guido van Rossum)。
2、python的优缺点:
优点:
简单,易学;
开发效率高;
高层语言;
可移植性好;
可扩展性好;
可嵌入性强;
拥有丰富的库。
缺点:
代码不能加密;
线程不能利用多CPU的问题。
二、python的安装
下载安装包:https://www.python.org/downloads/
安装
配置环境变量
三、Hello world程序
python:
# /usr/bin/env python
print("hello world")
C++
1 #include <iostream>
2 int main(void)
3 {
4 std::cout<<"Hello world";
5 }
java
1 public class HelloWorld{
2 // 程序的入口
3 public static void main(String args[]){
4 // 向控制台输出信息
5 System.out.println("Hello World!");
6 }
7 }
PHP
1 <?php
2 echo "hello world!";
3 ?>
Ruby
puts "Hello world."
四、变量
1、格式化输出的三种方式
name = input("name:")
age = int(input("age:") ) #integer
print(type(age) , type( str(age) ))
job = input("job:")
salary = input("salary:")
info = '''
-------- info of %s -----
Name:%s
Age:%d
Job:%s
Salary:%s
''' % (name,name,age,job,salary)
print(info)
info2 = '''
-------- info of {_name} -----
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
'''.format(_name=name,
_age=age,
_job=job,
_salary=salary)
print(info2)
info3 = '''
-------- info of {0} -----
Name:{0}
Age:{1}
Job:{2}
Salary:{3}
'''.format(name,age,job,salary)
print(info3)
五、循环
while循环(猜数游戏)
age_of_oldboy = 56
count = 0
while count <3:
guess_age = int(input("guess age:") )
if guess_age == age_of_oldboy :
print("yes, you got it. ")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger!")
count +=1
if count == 3:
countine_confirm = input("do you want to keep guessing..?")
if countine_confirm != 'n':
count =0
输出结果
for循环
age_of_oldboy = 56
for i in range(3):
guess_age = int(input("guess age:") )
if guess_age == age_of_oldboy :
print("yes, you got it. ")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger!")
else:
print("you have tried too many times..fuck off")
输出结果
六、条件语句
if...else(用户登录)
_usrname = 'yimi'
_password = "1234"
name = input("name:")
password = input("password:")
if name == _usrname and password == _password:
print("welcome")
else:
print("you are wrong")
输入密码时,如果要不可见,可以使用getpass模块中的getpass方法
import getpass
_usrname = 'yimi'
_password = "1234"
name = input("name:")
password = getpass.getpass("password:")
if name == _usrname and password == _password:
print("welcome")
else:
print("you are wrong")
输出结果