Python Learning——第一天

屏幕输出指令 ——print "Welcome to Python!"

定义变量 ——my_bool = 10(自动识别数据类型)

my_float=1.23

结构代码 ——空白,即是缩进来表现结构,而非c的;

注释 ——#后;多行注释用三组引号括起来" " "bla..bla.." " "

计算 ——+ - * /;幂计算2**3(2的三次方);取余%

string ——" "括起来定义,若想在其中加入单引号,在前添加\;c="cats"[0](下标输出制定字符);

len(string)返回string长度;parrot.lower()所有字符小写;parrot.upper()大写;

str(2)将2转换为“2”,即转换为字符串;isalpha()判断是否全为字母;

[1:len(new_word)]分割string

输出 ——print anything;print"Life " + "of " +"Brian";

print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)

name = raw_input("What is your name?")
quest= raw_input("What is your quest?")
color = raw_input("What is your favorite color?")


print "Ah, so your name is %s, your quest is %s, " \
"and your favorite color is %s." % (name, quest, color)

导入库 ——from datetime import datetime

记录当前时间 ——now=datetime.now();now.year;now.month;now.day;now.hournow.minute, and now.second.

输入 ——answer = raw_input("Type left or right and hit 'Enter'.").lower()

函数定义 ——def square(n):
    """Returns the square of a number."""
    squared = n**2
    print "%d squared is %d." % (n, squared)
    return squared

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值