Êý¾ÝÀàÐÍÏà¹ØÁ·Ï°
Êý¾ÝÀàÐÍÏà¹ØÁ·Ï°
X=int('ABCD',16)
print(X)
type(X)
a = 5.99
b = str(a)
print(b)
a = 520.11
d = float(a)
d
print(d)
a = 520.11
e = int(a)
e
print(e)
a_string='hello'+''+"Women Who Code!"
print(a_string)
print("str[0]:"+a_string[0])
print("str[2:5]:" + a_string[2:5])
print("str[2:] :" + a_string[2:])
43981
5.99
520.11
520
helloWomen Who Code!
str[0]:h
str[2:5]:llo
str[2:] :lloWomen Who Code!
Áбí²Ù×÷
lis = [ "WWCode", 786 , 2.23, 'singapore', 70.2 ]
print(lis[0:3])
type(lis)
lis = [ "WWCode", 786 , 2.23, 'singapore', 50 ]
print(lis[3][0:4])
print(lis[3][0:4])
lis[2] = 3.3
print(lis)
symbols = '$¡é¡ê£¤€¡è'
codes = [ord(symbol) for symbol in symbols]
codes
['WWCode', 786, 2.23]
sing
sing
['WWCode', 786, 3.3, 'singapore', 50]
[36, 162, 163, 165, 8364, 164]
Ôª×é²Ù×÷
t1 = ( "WWCode", 100000 , 0.5 )
t2 = 'Singapore', 1160.5
t_singleton = ('We',)
t_empty = ()
print(type(t1)); print(type(t2))
print(t_singleton);
type(t_empty)
<class 'tuple'>
<class 'tuple'>
('We',)
tuple
×Öµä²Ù×÷
×ÖµäÊÇÁíÒ»ÖֿɱäÈÝÆ÷Ä£ÐÍ,ÇÒ¿É´æ´¢ÈÎÒâÀàÐͶÔÏó¡£
×ÖµäµÄÿ¸ö¼üÖµ key=>value ¶ÔÓÃðºÅ : ·Ö¸î,ÿ¸ö¼üÖµ¶ÔÖ®¼äÓöººÅ , ·Ö¸î,Õû¸ö×Öµä°üÀ¨ÔÚ»¨À¨ºÅ {} ÖÐ
dict1 = {'name':'Women Who Code Singapore',
'org':'WWCode',
'city':'Singapore',
'members':1260}
print(dict1['org'])
type(dict1)
dict1['rank'] = 10
dict1['abcde']=10000
print(dict1)
dict1['org']
print(dict1['org'])
dict1.get('org','²»´æÔÚ')
dict1.get('ord','²»´æÔÚ')
WWCode
{'name': 'Women Who Code Singapore', 'org': 'WWCode', 'city': 'Singapore', 'members': 1260, 'rank': 10, 'abcde': 10000}
WWCode
'²»´æÔÚ'
Sets ¼¯ºÏ
¼¯ºÏ(set)ÊÇÒ»¸öÎÞÐòµÄ²»Öظ´ÔªËØÐòÁС£
¿ÉÒÔʹÓôóÀ¨ºÅ { } »òÕß set() º¯Êý´´½¨¼¯ºÏ,×¢Òâ:´´½¨Ò»¸ö¿Õ¼¯ºÏ±ØÐëÓà set() ¶ø²»ÊÇ { },ÒòΪ { } ÊÇÓÃÀ´´´½¨Ò»¸ö¿Õ×ֵ䡣
´´½¨¸ñʽ:parame = {value01,value02,...}
»òÕß
set(value)
wwcode_asia_networks = {'Bangalore','Beijing','Chennai','Delhi','Gujarat','Hong Kong','Kuala Lumpur'}
type(wwcode_asia_networks)
print(wwcode_asia_networks)
wwcode_asia_networks .remove('Delhi')
print(wwcode_asia_networks)
wwcode_asia_networks.pop()
print(wwcode_asia_networks)
t =set(("Bangalore","Beijing"))
'Hong Kong' in t
wwcode_asia_networks.update({1,3})
wwcode_asia_networks=t
print(t)
len(wwcode_asia_networks)
wwcode_asia_networks=t
t.add(500)
print(t)
wwcode_asia_networks.clear()
print(wwcode_asia_networks)
ÔËËãºÍ²¼¶ûÔËËã
#ÔËËã·û ÃèÊö ʵÀý = ¼òµ¥µÄ¸³ÖµÔËËã·û c = a + b ½« a + b µÄÔËËã½á¹û¸³ÖµÎª c += ¼Ó·¨¸³ÖµÔËËã·û c += a µÈЧÓÚ c = c + a -= ¼õ·¨¸³ÖµÔËËã·û c -= a µÈЧÓÚ c = c - a *= ³Ë·¨¸³ÖµÔËËã·û c *= a µÈЧÓÚ c = c * a /= ³ý·¨¸³ÖµÔËËã·û c /= a µÈЧÓÚ c = c / a %= È¡Ä£¸³ÖµÔËËã·û c %= a µÈЧÓÚ c = c % a **= Ãݸ³ÖµÔËËã·û c **= a µÈЧÓÚ c = c ** a //= È¡Õû³ý¸³ÖµÔËËã·û c //= a µÈЧÓÚ c = c // a
x = 1 + 2
y = 3 - 4
z = 5 * 6
a = z / y
b = z % x
c = y ** x
d = c // x
print(b)
print("x:" + str(x) + " y:" + str(y) + " z:" + str(z) +
" a:" + str(a) + " b:" + str(b) + " c:" + str(c) + " d:" + str(d))
x=2
y=4
c=x**y
print(c)
x=9
y=2
c=x//y
print(c)
print(a == b)
print(a != b)
print(a > b)
print(a < b)
print(a >= b)
print(a <= b)
0
x:3 y:-1 z:30 a:-30.0 b:0 c:-1 d:-1
16
4
False
True
False
True
False
True
a_string = "Women Who Code"
print("Women" in a_string)
print("Men" not in a_string)
print(len("Women Who Code") is len(a_string))
print(len("Hello World!") is not len(a_string))
x = [1, 2, 3]
y = [1, 2, 3]
print(x == y)
print(x is y)
print(id(x))
print(id(y))
x = (1, 2, 3)
y = (1, 2, 3)
print(x == y)
print(x is y)
print(id(x))
print(id(y))
x = {"id": 1, "name": "Tom", "age": 18}
y = {"id": 1, "name": "Tom", "age": 18}
print(x == y)
print(x is y)
print(id(x))
print(id(y))
x = set([1, 2, 3])
y = set([1, 2, 3])
print(x == y)
print(x is y)
print(id(x))
print(id(y))
x = [1, 2, 3]
y = x
print(x == y)
print(x is y)
print(id(x))
print(id(y))
none_type = None
none_type is None
True
True
True
True
True
False
1824923598400
1824927357440
True
False
1824934194112
1824923855360
True
False
1824931618560
1824923598208
True
False
1824925829376
1824935470688
True
True
1824927358016
1824927358016
True
|