Python代码片段(四)

Python代码片段

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#这是一段注释
a = 1000
if a > 100:
    print('中文:a > 100')
else: 
	print('a <= 100');

names = ['Rick','Ashley','Mike']

#for循环操作
for name in names :
	print(name)

#自定义函数
def my_fun(age):
    if age <= 20:
    	print("young man")
    else:
    	print("old man")	
    return 2,'Mike'   	

#先定义后使用
res = my_fun(17)  

#返回一个元组tuple
print(res[1])

Python基础(三)

基础学习

下面是一个Python的代码程序片段

#这是一段注释
a = 1000
if a > 100:
print('a > 100')
else: 
print('a <= 100');

#后面跟注释语句,其他没行都是一个“有效”的语句,当语句以:结尾时,缩进语句视为代码块,缩进的另一个好处是强迫你写出缩进较少的代码,你会倾向于把一段很长的代码拆分成若干函数,从而得到缩进较少的代码。

Python是大小写敏感的。

1.数据类型和变量

  1. Python可以处理任意类型的数字,程序的表现方法跟数学是一致的:1,0,-100;浮点数也就是小数,之所以称为浮点数,是因为按照科学记数法表示时,一个浮点数的小数点位置是可变的,比如,1.23×109和12.3×108是完全相等的。浮点数可以用数学写法,如1.23,3.14,-9.01,等等。但是对于很大或很小的浮点数,就必须用科学计数法表示,把10用e替代,1.23×109就是1.23e9,或者12.3e8,0.000012可以写成1.2e-5,等等
  2. 浮点小数:浮点数也就是小数,之所以称为浮点数,是因为按照科学记数法表示时,一个浮点数的小数点位置是可变的,比如,1.23×109和12.3×108是完全相等的。浮点数可以用数学写法,如1.23,3.14,-9.01,等等。但是对于很大或很小的浮点数,就必须用科学计数法表示,把10用e替代,1.23×109就是1.23e9,或者12.3e8,0.000012可以写成1.2e-5,等等    
  3. 字符串

         用’或””表示括起来任何文本,比如’abc’,”efg”。如何文本中包含’或者”,可以通过\进行转义,列如:

'I\'m \"OK\"!'

表示的是

I'm "OK"!

2. 布尔值

Python中用True和False表示,注意大小写

3.空值

Python中用None表示空值,None不能理解0,因为0是有意义的

4.变量

a = 100

b = a

a = ‘100’

c = 10

    

Python环境搭建(二)

Note:Python是在3.x下搭建的,所有后续的教程都是基于3.x讲解的。

软件下载:

https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi

安装:

下载完成之后,双击完成安装。

安装过程中需要注意配置,环境变量path:D:\develop\Python34\python.exe

在cmd下输入python,会出现,表示安装成功。

第一个Python程序:

1. 在控制台输入:计算100与200相加

>>> 100 + 200
300
>>>

2. 控制台打印:

>>> print('hello world')
hello world
>>>

最后可以通过exit(),退出控制台

Python简介(一)

Python WiKi:

Python是一种面向对象、直译式的计算机程序语言,具有近二十年的发展历史。它包含了一组功能完备的标准库,能够轻松完成很多常见的任务。它的语法简单,与其它大多数程序设计语言使用大括号不一样,它使用缩进来定义语句块。与Scheme、Ruby、Perl、Tcl等动态语言一样,Python具备垃圾回收功能,能够自动管理内存使用。Python是解释型语言,Python的官方解释器是CPython,该解释器用C语言编写,是一个由社区驱动的自由软件,目前由Python软件基金会管理。

优势

而不同的编程语言,干同一个活,编写的代码量,差距也很大。
比如,完成同一个任务,C语言要写1000行代码,Java只需要写100行,而Python可能只要20行。

所以Python是一种相当高级的语言。Python可以做很多的事情,比如自动备份你的MP3;可以做网站,很多著名的网站包括YouTube就是Python写的;可以做网络游戏的后台,很多在线游戏的后台都是Python开发的。

劣势

相比C,运行速度较慢。不适合做移动应用。iPhone(swift/object-c)Android(java andriod)

10 Excellent Pictures To Show What’s Wrong With Our Society

Jean Jullien is a French artist currently living in London. He is up for all sorts of graphics. Here are 10 of his powerful and honest illustrations to show what’s wrong about modern society:

1.Apple watch

People are so preoccupied with technology. Many of us spend large amount of time and energy consumed usually on smartphones, laptops, and/or Apple products. But do we really get freedom with these things, or we get more attached than ever? Moderation is the key.

2.Tinder

Do you think this is a relationship goal? I think not. This is an honest scenario where two people, supposed to be a couple, are so engaged with internet-connected gadgets which may be powering down the relationship.

3.Time

Everything we do requires time. But sadly, we can’t manage time. We can only manage ourselves. We set priorities because we can’t do everything all at once. It is hard to avoid the fact that we are running out of time. The problem with some people is they depend on “tomorrow”, but “tomorrow” will always have the same amount of time as “today”.

4.Fashion

One ultimate misconception about fashion is people need to be always up to date. But frankly, people are not necessarily responsible to always follow the latest trends. Dress what works for you and what makes you feel comfortable about yourself.

5.Fat or fit

FIT, NOT FAT!

Admit it, some people used to judge others based on the looks alone. Stop judging and start realizing: fat people are not always in bad health, same as healthy people are not always in ideal body shape.

6.Racism

Racism is prevalent. It has claimed too many lives. Everybody must be aware: humanity, not skin color, defines us.

7.Violence

Violence is never the answer! You don’t answer violence with violence. There’s no way we could get justice through it.

8.Warfare

It’s a shame how people can be this insensitive. People, who prioritize taking pictures or such selfish acts instead of helping other people, are seriously terrifying!

9.Selfie

Selfies are everywhere. But hey, what’s wrong with selfie–it’s just a picture?! Actually, there’s nothing wrong with selfies. Not until it happens to some people in social media, and as a part of common social issues, that selfies affect their self esteem and make them feel superior or inferior depending on how society judge them.

10.Listen

Blessed are those who are able to hear; gifted are those who are able to understand. People who do not listen are those you don’t need to share your life with.