python简单小记

我的环境windows,editplus,python-2.7.6。

1.带参数输出:

list = {'zhang','wang','li','zhao'}
for s in list:
	print('my first name is {0}'.format(s))


输出结果:

---------- Python ----------
my first name is zhao
my first name is zhang
my first name is wang
my first name is li

输出完成 (耗时 0 秒) - 正常终止


2.把上面那个例子list的值写成汉字,会报错:

   SyntaxError: Non-ASCII character '\xe5' in file jichu.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

   因为python默认没有汉字,这里要改变编码,在文件开头写上:#coding=utf-8修改结果如下:

 

#coding=utf-8
list = {'张','王','李','赵'}
for s in list:
	print('my first name is {0}'.format(s))
	

输出结果:

---------- Python ----------
my first name is 李
my first name is 赵
my first name is 张
my first name is 王

输出完成 (耗时 0 秒) - 正常终止

3.python中的类:

 

class Hello:
	def __init__ (self,name):
		self._name = name
	def say(self):
		print('hello {0}'.format(self._name))
	
class Hai:
	def __init__ (self,name):
		hello._init(self,name)
	def sayHai (self):
		print('hai {0}'.format(self.name))

h = Hello("zhang san")
h.say()

输出:

---------- Python ----------
hello zhang san

输出完成 (耗时 0 秒) - 正常终止

4.引入python文件

  法1:

import jichu1

h = jichu1.Hello('lisi')
h.say()

法2:

from jichu1 import Hello

h = Hello('lisi')

h.say()

区别显而易见。

只是一些很基础的知识。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值