IDE:IDLE (Integrated Development and Learning Environment)综合开发和学习环境

交互模式 编辑器模式 file -> new file

.py为python文件格式

ALT + P:输出上一句代码


在编译器中输入指令:import this后,编译器会输出一首诗

The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- let's do more of those!

第一个py程序-猜数字游戏

temp = input("猜猜我是谁")

guess = int(temp)



if guess == 8:

    print("猜猜你猜对了没")

    print("猜对啦!!!")

else:

    print("sb")



print("略略略")

变量与字符串

与C语言规则类似,但比C语言更加神奇

比如,交换x,y的值:

x = 3

y = 5

x,y = y,x

此时x的值为5,y的值为3


字符串主要有三种形式

Single quotes

print('I love ACM.')

Double quotes

print("Let's go")

Triple quotes(长字符串)('''内容''')("""内容""")(与多行注释相似)

print('''I love CCPC''')

使用不同个数的引号明显有一个好处:可以输出包含不同引号的内容,比如Let's go这样的句子,明显不可以用Single quotes输出,如果遇到了嵌套极为复杂的情况,可以使用转义字符.

符号 说明
\\ 反斜杠()
\' 单引号(')
\" 双引号(")
\a 响铃(BEL)
\b 退格符(BS)
\n 换行符(LF)
\t 水平制表符(TAB)
\v 垂直制表符(VT)
\r 回车符(CR)
\f 换页符(FF)
\ooo ooo为八进制数
\xhh hh为十六进制数

text:请输出以下内容:

"Rush B!!!"

"ACM真是'太有趣啦'"

输出114514的八进制表示

As we all know,这些都不难

向着打表前进!!!

打印出编译器所在的文件地址


原始字符串:

print(r"\n")

输出为:\n

在输出内容之前加上"r",输出内容中的转义字符将会失效.


字符串的加法和乘法:

如果在python编译器中输入:

'114514'+'1919810'

结果会是什么?

print("ACM真是太有趣啦\n" * 100)

这样写结果又会是什么呢?

建议大家试一下

0 条评论

目前还没有评论...