ºÃÎĵµ - רҵÎÄÊéд×÷·¶ÎÄ·þÎñ×ÊÁÏ·ÖÏíÍøÕ¾

Python»ù´¡Óï·¨

ÓÉ ÌìÏ ·ÖÏí ʱ¼ä£º ¼ÓÈëÊÕ²Ø ÎÒҪͶ¸å µãÔÞ

µÚÒ»Õ ¸ñʽ¹æ·¶

Ò»¡¢Í·Îļþ£º 1. ×¢ÊÍÐÐ

#!/usr/bin/python3 # -*- coding: UTF-8 -*-

2. µ¼ÈëÄ£¿éÐÐ

µ¼ÈëÕû¸öÄ£¿é£¬¸ñʽ£º?

import module

µ¼ÈëÄ£¿éÖÐÈ«²¿º¯Êý£¬¸ñʽΪ£º? from module import *

¶þ¡¢±êʶ·û

Ê××Ö·û±ØÐëÊÇ×Öĸ»òÏ»®Ïß¡£ ±êʶ·û¶Ô´óСдÃô¸Ð¡£

Èý¡¢±£Áô×Ö

33¸ö±£Áô×Ö£º

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class',

'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] ËÄ¡¢×¢ÊÍ

1. µ¥ÐÐ×¢ÊÍ È磺# µÚ¶þ¸ö×¢ÊÍ 2. ¶àÐÐ×¢ÊÍ È磺\

µÚÈý×¢ÊÍ µÚËÄ×¢ÊÍ

\Îå¡¢ÐÐÓëËõ½ø

1. ͨ³£ÊÇÒ»ÐÐдÍêÒ»ÌõÓï¾ä£¬µ«Èç¹ûÓï¾äºÜ³¤£¬ÎÒÃÇ¿ÉÒÔʹÓ÷´Ð±¸Ü(\\)À´Êµ

ÏÖ¶àÐÐÓï ¾ä£¬ÔÚ [], {}, »ò () ÖеĶàÐÐÓï¾ä£¬²»ÐèҪʹÓ÷´Ð±¸Ü(\\)¡£

2. Ò»°ãËõ½øËĸö¿Õ¸ñ

µÚ¶þÕ ÔËËã·ûÓë±í´ïʽ

ËãÊõÔËËã·û

±È½Ï£¨¹Øϵ£©ÔËËã·û ¸³ÖµÔËËã·û Âß¼­ÔËËã·û

µÚÈýÕ Êý¾ÝÀàÐÍ

Áù¸ö±ê×¼Êý¾ÝÀàÐÍÖУº

²»¿É±äÊý¾Ý£ºNumber£¨Êý×Ö£©¡¢String£¨×Ö·û´®£©¡¢Tuple£¨Ôª×飩¡¢Sets£¨¼¯ºÏ£©£» ¿É±äÊý¾Ý£º List£¨ÁÐ±í£©¡¢Dictionary£¨×ֵ䣩¡£

£¨Ò»£©Êý×Ö

1. Python Ö§³Ö³£ÓÃÊýÖµÀàÐÍ£º

ÕûÐÍ(Int)?

Õý»ò¸ºÕûÊý£¬²»´øСÊýµã¡£Python3 ÕûÐÍÊÇûÓÐÏÞÖÆ´óС

µÄ¡£

¸¡µãÐÍ(float)?

ÓÉÕûÊý²¿·ÖÓëСÊý²¿·Ö×é³É¡£

2. Python Êý×ÖÀàÐÍת»»

Ö»ÐèÒª½«Êý¾ÝÀàÐÍ×÷Ϊº¯ÊýÃû¼´¿É¡£ int(x)?½«xת»»ÎªÒ»¸öÕûÊý¡£ float(x)?½«xת»»µ½Ò»¸ö¸¡µãÊý¡£

3.ÄÚÖú¯Êý

£¨¶þ£©×Ö·û´® 1. ´´½¨×Ö·û´®,È磺var1 = 'Hello World!' 2. ·ÃÎÊ×Ö·û´®£¬È磺var1 = 'Hello World!' print (\3. ×Ö·û´®¸üР¿ÉÒÔ½ØÈ¡×Ö·û´®µÄÒ»²¿·Ö²¢ÓëÆäËû×Ö¶ÎÆ´½Ó£¬È磺 var1 = 'Hello World!' print (\ÒѸüÐÂ×Ö·û´® : \4. תÒå×Ö·û \\n \\v \\t »»ÐÐ ×ÝÏòÖƱí·û ºáÏòÖƱí·û 5. ×Ö·û´®²Ù×÷

6. ×Ö·û´®¸ñʽ»¯

7. ×Ö·û´®ÄÚÖú¯Êý

£¨Èý£©Áбí

1. ´´½¨ÁÐ±í£¬È磺

list1 = ['Google', 'Runoob', 1997, 2000]

2. ·ÃÎÊÁбíÖеÄÖµ

list2 = [1, 2, 3, 4, 5, 6, 7 ] print (\

3. ¸üÐÂÁбí

list = ['Google', 'Runoob', 1997, 2000] print (\µÚÈý¸öÔªËØΪ : \list[2] = 2001

4. ɾ³ýÁбíÔªËØ list = ['Google', 'Runoob', 1997, 2000] del list[2] 5. Áбí¶Ô + ºÍ * µÄ²Ù×÷·ûÓë×Ö·û´®ÏàËÆ¡£+ ºÅÓÃÓÚ×éºÏÁÐ±í£¬* ºÅÓÃÓÚÖظ´ÁÐ±í¡£ 6. Áбí½ØÈ¡ÓëÆ´½Ó L[1:] ['Runoob', 'Taobao'] 7.ÁбíÄÚÖú¯Êý Êä³ö´ÓµÚ¶þ¸öÔªËØ¿ªÊ¼ºóµÄËùÓÐÔªËØ

8. ÁÐ±í³£Ó÷½·¨ £¨ËÄ£©Ôª×é

1. ´´½¨Ôª×飬È磺tup1 = ('Google', 'Runoob', 1997, 2000);

tup1 = (50,) Ôª×éÖÐÖ»°üº¬Ò»¸öÔªËØʱ£¬ÐèÒªÔÚÔªËغóÃæÌí¼Ó¶ººÅ¡£

2. ·ÃÎÊÔª×é

tup1 = ('Google', 'Runoob', 1997, 2000) tup2 = (1, 2, 3, 4, 5, 6, 7 ) print (\print (\

3. ɾ³ýÔª×é

Ôª×éÖеÄÔªËØÖµÊDz»ÔÊÐíɾ³ýµÄ£¬µ«¿ÉÒÔÓÃdelÓï¾äÀ´É¾³ýÕû¸öÔª×飬Èç:

tup = ('Google', 'Runoob', 1997, 2000) print (tup) del tup;

4. Ôª×éÔËËã·û Ôª×éÖ®¼ä¿ÉÒÔʹÓà + ºÅºÍ * ºÅ½øÐÐÔËËã¡£ Python ±í´ïʽ ½á¹û len((1, 2, 3)) ('Hi!',) * 4 5. Ôª×éË÷Òý£¬½ØÈ¡ L = ('Google', 'Taobao', 'Runoob') ±í´ïʽ ½á¹û L[2] L[-2] L[1:] 'Runoob' 'Taobao' ('Taobao', 'Runoob') 3 ('Hi!', 'Hi!', 'Hi!', 'Hi!') (1, 2, 3) + (4, 5, 6) (1, 2, 3, 4, 5, 6) ÃèÊö ¼ÆËãÔªËظöÊý Á¬½Ó ¸´ÖÆ ÃèÊö ¶ÁÈ¡µÚÈý¸öÔªËØ ·´Ïò¶ÁÈ¡£»¶ÁÈ¡µ¹ÊýµÚ¶þ¸öÔªËØ ½ØÈ¡ÔªËØ£¬´ÓµÚ¶þ¸ö¿ªÊ¼ºóµÄËùÓÐÔªËØ¡£ 6. Ôª×éÄÚÖú¯Êý £¨Î壩×Öµä

1. ´´½¨×ֵ䣬È磺dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'}

2. ·ÃÎÊ×ÖµäÀïµÄÖµ

dict = {'Name': 'Runoob', 'Age': 7, 'Class': 'First'} print (\ print (\

3. ÐÞ¸Ä×Öµä

Ïò×ÖµäÌí¼ÓÐÂÄÚÈݵķ½·¨ÊÇÔö¼Óеļü/Öµ¶Ô£¬Ð޸Ļòɾ³ýÒÑÓмü/Öµ¶Ô£¬Èç: dict = {'Name': 'Runoob', 'Age': 7, 'Class': 'First'} dict['Age'] = 8; # ¸üРAge dict['School'] = \²ËÄñ½Ì³Ì\Ìí¼ÓÐÅÏ¢

4. ɾ³ý×ÖµäÔªËØ

dict = {'Name': 'Runoob', 'Age': 7, 'Class': 'First'} del dict['Name'] # ɾ³ý¼ü 'Name' () # Çå¿Õ×Öµä

Python»ù´¡Óï·¨

µÚÒ»Õ¸ñʽ¹æ·¶Ò»¡¢Í·Îļþ£º1.×¢ÊÍÐÐ#!/usr/bin/python3#-*-coding:UTF-8-*-2.µ¼ÈëÄ£¿éÐе¼ÈëÕû¸öÄ£¿é£¬¸ñʽ£º?importmoduleµ¼ÈëÄ£¿éÖÐÈ«²¿º¯Êý£¬¸ñʽΪ£º?frommoduleimpor
ÍƼö¶È£º
µã»÷ÏÂÔØÎĵµÎĵµÎªdoc¸ñʽ
95y7z9olix036aw5tvxo0daes3y30z00x3k
ÁìÈ¡¸£Àû

΢ÐÅɨÂëÁìÈ¡¸£Àû

΢ÐÅɨÂë·ÖÏí