2 paython開発基盤(2)

10540 ワード

*—*—python    (2)—*—*
、while
1.while :



:number = 1 # :1
while number < 4: 2
print(number) 3
number = number + 1

2.
while True: # 1
print('111') 1
print('123321123') 1
..... 1,
ps:while ,

3.while ——
break continue
:flag = True
while flag: # 111
print('111')
flag = False
——————break ——————
while True: # 111
print('111')
break
——————continue ——————
while True: # , q :11
inp = input(' , q :') 11
if inp == 'q': , q :15
continue 15
print(inp) , q :q
, q

continue :
count = 1
while count <= 5:
if count == 3: # 1
count += 1 2
countinue 4
print(count) 5
count += 1

4.while......else...
else while , break , else
break , while.....else... ;
count = 1 # 1
while count <= 5: 2
print(count) 3
count += 1 4
else: 5
print('bye') bye
——————————————————————————————————————
count = 1
while count <= 5: # 2
count += 1 3
if count == 4: bye
break
print(count)
else:
print('hahahaha')
print('bye')


1.
%d—— %s——
:18 Ethan
:age = 18
name = "Ethan"
location = " "
behavior = " "
print("%d %s %s%s"%(age,name,location,behavior))
#print("%s %s %s%s"%(age,name,location,behavior))
#print(str(age)+" "+name+" "+location+behavior)
# :18 Ethan

ps: % %, %% python %% %
#print(" %s, 30%% python " % (name))


1.


+ -
- -
* -
/ - a b
% -
** - a b
// -



: 
       


2.


== ,
!= -
<> - , != 。(Python3 )
> - a b
< - a b。
>= - a b。
<= - a b。






3.
① :
and: , ,
or: , , .
not: , .
:() => not => and => or

②.x or y x 0, y

x 0, x

,and or


and a and b " " - a False,a and b False, b 。
or a or b " " - a 0, a , b 。
not not a " " - a True, False 。 a False, True。






4. in not in


in True, False。
not in True, False。

: list = [1,2,3,4,5]
print( True if 1 in list else False)
# True

5.


=
+=
-=
*=
/=
%=
**=
//=

6. id


is is
is not is not



1. ascii. . . 8 ( )
2. unicode. . 32 4
3. UTF-8. unicode.
: 8 . 1
:16 . 2
. 24 . 3
4. GBK. 、 . 16 2 .

8bit = 1byte
1024byte = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB

転載先:https://www.cnblogs.com/python-wang/p/9508677.html