输出语句
python没有int float等数据类型1
print('welcome to python')1
welcome to python1
print('hello '+' world')1
hello world1
print('i love u\n'*5)1
i love ui love ui love ui love ui love u12345
输入语句
temp=input('please input a number:')
guess=int(temp)if guess==3:
print('equal me ^-^')
else:
print('not equal me :)')123456
please input a number:1not equal me :)12
BIF=built in function 内置函数
dir(__builtins__)1
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__IPYTHON__', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'display', 'divmod', 'enumerate', 'eval', 'exec', 'filter', 'float', 'format', 'frozenset', 'get_ipython', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
help(input)1
Help on method raw_input in module ipykernel
.kernelbase:raw_input(prompt='')
method of ipykernel.ipkernel.IPythonKernel instance
Forward raw_input to frontends
Raises ------
StdinNotImplentedError if active frontend doesn't support stdin.12345678
最后,如果你的时间不是很紧张,并且又想快速的提高,最重要的是不怕吃苦,建议你可以联系维:762459510 ,那个真的很不错,很多人进步都很快,需要你不怕吃苦哦!大家可以去添加上看一下~
变量
python 没有“变量” 只有 ‘名字’1
name='lifat'print(name)name='add lifat'name1234
lifat'add lifat'1234567
first=1second=3print(first+second)123
41
变量名可以包括字母、数字、下划线,但是不能以数字开头
字母可以大写也可以小写,python区分大小写
字符串
print('let's GO')1
let's GO1
print('C:\now')1
C:\now1
原始字符串
st=r'let\n'print(st)12
let\n1
st=r'let's go'#这里有一些问题print(st)12
let's go1
三重引号
st="""I,LOVE,you."""st12345
'I,\nLOVE,\nyou.\n'1
print(st)1
I,LOVE,you.123
条件分支
if语句
if 1==1: print('dddddd')else: print('bbbb')1234
dddddd1
while循环
temp=input('please input a number:')
k=int(temp)while k!=2:
temp=input('please input a number:')
k=int(temp)
123456
please input a number:21
for循环
range()这个BIF可以使用
help(range)1
Help on class range in module builtins:class range(object) |
range(stop) -> range object |
range(start, stop[, step]) -> range object | |
Return an object that produces a sequence of integers from start (inclusive) |
to stop (exclusive) by step.
range(i, j) produces i, i+1, i+2, ..., j-1. |
start defaults to 0, and stop is omitted!
range(4) produces 0, 1, 2, 3. |
These are exactly the valid indices for a list of 4 elements. |
When step is given, it specifies the increment (or decrement). | |
Methods defined here: | |
__bool__(self, /) |
self != 0 | |
__contains__(self, key, /) |
Return key in self. | |
__eq__(self, value, /) |
Return self==value. | |
__ge__(self, value, /) |
Return self>=value. | |
__getattribute__(self, name, /) |
Return getattr(self, name). | |
__getitem__(self, key, /) |
Return self[key]. | |
__gt__(self, value, /) |
Return self>value. | |
__hash__(self, /) |
Return hash(self). | |
__iter__(self, /) |
Implement iter(self). | |
__le__(self, value, /) |
Return self<=value. | |
__len__(self, /) |
Return len(self). | |
__lt__(self, value, /) |
Return self<value. | |
__ne__(self, value, /) |
Return self!=value. | |
__reduce__(...) |
Helper for pickle. | |
__repr__(self, /) |
Return repr(self). | |
__reversed__(...) |
Return a reverse iterator. | |
count(...) | rangeobject.count(value) -> integer -- return number of occurrences of value | |
index(...) |
rangeobject.index(value) -> integer -- return index of value. |
Raise ValueError if the value is not present. |
| ---------------------------------------------------------------------- |
Static methods defined here: |
| __new__(*args, **kwargs) from builtins.type |
Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | |
start | |
step | | stop1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
两个关键语句
break 退出循环continue 中止本轮循环12
temp=input('please input a number:')
k=int(temp)while k!=1:
temp=input('please input a number:')
k=int(temp)
if k==4:
break
elif k==3:
continue
print('Test')
1234567891011
please input a number:2please input a number:3please input a number:2Testplease input a number:5Testplease input a number:41234567
python的数据类型
整型,布尔类型,浮点型,e记法1
"520"+'das'1
'520das'1
a=150000000000000000a12
1500000000000000001
15e101
150000000000.01
b=0.00000000000000002b12
2e-171
True+True1
21
False+True1
11
转化
int()str()float()123
获得数据类型
type()isinstance()12
type("dddd")1
str1
a='ddddd'isinstance(a,str)#这里判断str有问题,是因为上面用str去定义变量12
--------------------------------------------------------------------
TypeError
Traceback (most recent call last)<ipython-input-150-dd385436226d> in <module>
1 a='ddddd'---->
2 isinstance(a,str)
#这里判断str有问题,是因为上面用str去定义变量TypeError: isinstance() arg
2 must be a type or tuple of types12345678910
help(str)1
No Python documentation found for 'I,
\nLOVE,\nyou.'.Use help() to get the interactive help utility
.Use help(str) for help on the str class.123
基本操作符
算术操作符
+ - * / ** // %1
4**51
10241
9//21
41
9%21
11
逻辑操作符
and or not1
not True1
False1
True and True1
True1
True and False1
False1
True or False1
True1
三元操作符
x=4y=3small = x if x<y else ysmall1234
31
断言(assert)
当关键字后面的条件为假得到时候,程序自动崩溃并且抛出AssertionError1
1
- 本文的文字及图片来源于网络加上自己的想法,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。最后,如果你的时间不是很紧张,并且又想快速的提高,最重要的是不怕吃苦,建议你可以联系维:762459510 ,那个真的很不错,很多人进步都很快,需要你不怕吃苦哦!大家可以去添加上看一下~