python学习笔记(1)

来源:互联网 发布:python notebook 使用 编辑:程序博客网 时间:2024/05/13 14:24

显示编码:

>>> ord('a')
97
>>> ord('a');
97
>>> chr(66)
'B'
>>> ord('哈')
21704


python的标准化输出:

>>> '%s hhh' % "dd"
'dd hhh'
>>> name ="hhh";

>>> "hello %s,you are %d" % (name,12);
'hello hhh,you are 12'


从键盘输入:

a = input("please input a number");


函数定义:
def functionname( parameters ):
   "函数_文档字符串"
   function_suite
   return [expression]


在 python 中,strings, tuples, 和 numbers 是不可更改的对象,而 list,dict 等则是可以修改的对象。
不可更改对象相当于C++中的值传递
可更改相当于引用传递


调用函数时,缺省参数的值如果没有传入,则被认为是默认值。
如def printinfo( name, age = 35 ):
age默认值为35


模块导入:

importsupport

或者:

from modname import name1[, name2[, ... nameN]]

原创粉丝点击