Python 3 학습 노트 의 기초 강좌
__author__ = 'Administrator'
import subprocess
cmd="cmd.exe"
begin=101
end=200
while begin<end:
p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
stdin=subprocess.PIPE,stderr=subprocess.PIPE)
p.stdin.write("ping www.baidu.com
".encode())
p.stdin.close()
p.wait()
print ('execution result:%s'%p.stdout.read())
__author__ = 'Administrator'
#ide PyCharm Python3
# Python
import keyword
print(keyword.kwlist)
#
a,b,c,d=20,5.5,True,4+3j
print(type(a),type(b),type(c),type(d))
#
s = 'Yes,he doesn\'t'
print(s,type(s),len(s))
#
print('str'+'ing', 'my'*3)
#Python 2
word = 'Python'
print(word[0],word[5])
print(word[-1],word[-6])
#
word = 'ilovepython'
print(word[1:5])
print(word[:])
print(word[-10:-6])
#List( )
# 、 。 :
a = ['him', 25, 100, 'her']
print(a)
#list , , ,
a = [1, 2, 3, 4, 5]
print(a[2])
print(a + [6, 7, 8])
a[0]=22
print(a)
#
print(a[2:5])
#
a[2:5]=[]
print(a)
# (tuple) , 。
a = (1991, 2014, 'physics', 'math')
print(a, type(a), len(a))
# (set) 。
student = {'Tom', 'Jim', 'Mary', 'Tom', 'Jack', 'Rose'}
print(student) #
print('Rose' in student)
#
a = set('abracadabra')
b = set('alacazam')
print(a)
print(a - b)# a b
print(a | b) # a b
print( a & b) # a b
#http://www.w3cschool.cc/python3/python3-data-type.html
# (mapping type), : 。 , , 。
dic = {} #
tel = {'Jack':1557, 'Tom':1320, 'Rose':1886}
print(tel)
print(tel['Jack']) # : key
del tel['Rose'] #
tel['Mary'] = 4127 #
print(tel)
print(list(tel.keys())) # key list
print(sorted(tel.keys())) # key
print('Tom' in tel) #
print('Mary' not in tel) #
__author__ = 'yunshouhu'
import base64
'''
'''
"""
"""
#
print(5 ** 2) # 5
print(2 ** 7) # 2 7
print(2 ** 10)
print(2 ** 20)
#
a,b=0,1
while b<10:
print(str(b),end=',')
a,b=b,a+b
#base64
print("")
s=" nihao"
a=base64.b64encode(s.encode(encoding="utf-8"))
print(a.decode())
print(base64.b64decode(a).decode())
age=int(input("age of the dog:"))
print()
if age<0:
print("this can hardly be true!")
elif age==1:
print("about 14 humen years")
elif age==2:
print("about 22 human years")
elif age>2:
human=22+(age-2)*5
print("human years:",human)
else:
print("hehe")
#input("press return ")
#while
n = 100
sum = 0
counter = 1
while counter <= n:
sum = sum + counter
counter += 1
print("Sum of 1 until %d: %d" % (n,sum))
#for
languages = ["C", "C++", "Perl", "Python"]
for x in languages:
print(x)
#break
edibles = ["ham", "spam","eggs","nuts"]
for food in edibles:
if food == "spam":
print("No more spam please!")
break
print("Great, delicious " + food)
else:
print("I am so glad: No spam!")
print("Finally, I finished stuffing myself")
#
for i in range(0, 10) :
print(i)
for i in range(0, 10, 3) :
print(i)
#pass
pass # (Ctrl+C)
__author__ = 'yunshouhu'
#
def hellword():
print("helloworld ok!")
hellword()
def area(width,height):
return width*height;
def print_welcome(name):
print("Welcome ",name)
w=4
h=5
print("width=",w," height=",h," area=",area(w,h))
#
a = 4 #
def print_func1():
a = 17 #
print("in print_func a = ", a)
def print_func2():
print("in print_func a = ", a)
print_func1()
print_func2()
print("a = ", a)
#
def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
print("-- This parrot wouldn't", action, end=' ')
print("if you put", voltage, "volts through it.")
print("-- Lovely plumage, the", type)
print("-- It's", state, "!")
parrot(1000) # 1 positional argument
parrot(voltage=1000) # 1 keyword argument
parrot(voltage=1000000, action='VOOOOOM') # 2 keyword arguments
parrot(action='VOOOOOM', voltage=1000000) # 2 keyword arguments
parrot('a million', 'bereft of life', 'jump') # 3 positional arguments
parrot('a thousand', state='pushing up the daisies') # 1 positional, 1 keyword
#
def arithmetic_mean(*args):
sum = 0
for x in args:
sum += x
return sum
print(arithmetic_mean(45,32,89,78))
print(arithmetic_mean(8989.8,78787.78,3453,78778.73))
print(arithmetic_mean(45,32))
print(arithmetic_mean(45))
print(arithmetic_mean())
#
from collections import deque
queue = deque(["Eric", "John", "Michael"])
queue.append("Terry") # Terry arrives
queue.append("Graham") # Graham arrives
print(queue.popleft()) # The first to arrive now leaves
print(queue.popleft()) # The second to arrive now leaves
print(queue) # Remaining queue in order of arrival
#
knights = {'gallahad': 'the pure', 'robin': 'the brave'}
for k, v in knights.items():
print(k, v)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.