标签:fun text rev def error: prime ace span most
for n in range (2,100):
if n==2:
print(n)
continue
for i in range (2, n):
if (n %i) ==0:
break
else:
print(n)
注意对齐
打印质数改良版
def is_prime(n):
if(n<2):
return False
if(n==2):
return True
for m in range (2, int(n**0.5)+1):
if(n%m)==0:
return False
else:
return True
for i in range(80,110):
if is_prime(i):
print(i)
1.from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
11+10-9/8//7%5
‘3.14‘+3
运行结果
21.0
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-d1e427b7cc92> in <module>
2 InteractiveShell.ast_node_interactivity = "all"
3 11+10-9/8//7%5
----> 4 ‘3.14‘+3
TypeError: can only concatenate str (not "int") to str
2.from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
type(3)
type(3.0)
type(range(10))
type(‘3.14‘)
type(True)
type([1,2,3])
type({‘a‘:1,‘b‘:2,‘c‘:3})
type((1,2,3))
type({1,2,3})
int
float
range
str
bool
list
dict
tuple
set
3.from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
‘Python‘+‘Awesome‘
‘Python‘,‘Awesome‘
‘Python, ‘+‘Awesome! ‘ * 3
‘o‘ in ‘Awesome‘ and ‘o‘ not in ‘Python‘
运行结果:
‘PythonAwesome‘
(‘Python‘, ‘Awesome‘)
‘Python, Awesome! Awesome! Awesome! ‘
Falsefrom IPython.core.interactiveshell import InteractiveShell
4.
6.print(‘Hello‘,‘Jack‘,‘Mike‘,‘...‘,‘and all you guys‘)
Hello Jack Mike ... and all you guys
7.
name=‘ANN‘
age=‘22‘
print(f‘{name} is {age} years old.‘)
ANN is 22 years old.
8.
import sys
print(‘Hello‘,‘World‘)
print(‘Hello‘,‘World‘,sep=‘ ‘,end=‘\n‘,file=sys.stdout,flush=False)
print(‘Hello‘,‘World‘,sep=‘-‘,end=‘\t‘)
print(‘Hello‘,‘World‘,sep=‘~‘)
print(‘Hello‘,‘World‘,sep=‘\n‘)
Hello World Hello World Hello-World Hello~World Hello World
9.print(print(1))
1
None
10.
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity="all"
sorted(‘abcd‘)
sorted(‘abcd‘,reverse=True)
[‘a‘, ‘b‘, ‘c‘, ‘d‘]
[‘d‘, ‘c‘, ‘b‘, ‘a‘]
11.
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity="all"
divmod(11,3)
a,b=divmod(11,3)
a
b
(3,2)
3
2
12.
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity="all"
pow(2,3)
pow(2,3,4)
8
0
//pow(2,3,4):2^3%4
13.
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity="all"
bool()
bool(3.14159)
bool(-3.14159)
bool(1==2)
bool(None)
False
True
True
False
False
14.
from IPython.core.interactiveshell import InteractiveShellPlease tell me your age :an int number e.g. 22 18
16.
from IPython.core.interactiveshell import InteractiveShell0 P 1 y 2 t 3 h 4 o 5 n
please follow the number3.14: 3.14
3
28.26
4
‘Now is better than ever‘
‘Now Is Better Than Ever‘
‘nOW IS BETTER THAN EVER‘
‘nOW iS bETTER tHAN eVER‘
标签:fun text rev def error: prime ace span most
原文地址:https://www.cnblogs.com/wwqdata/p/11519737.html