

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Data types and Collections i n t e g e r 1 0 f l o a t 3. 1 4 b o o l e a n T r u e / F a l s e s t r i n g ‘ a b c d e ’ l i s t [ 1 , 2 , 3 , 4 , 5 ] t u p l e ( 1 , 2 , ‘ a ’ , ‘ b ’ ) s e t { ‘ a ’ , ’ b ’ , ’ c ’ } d i c t i o n a r y { ‘ a ’ : 1 , ‘ b ’ : 2 } Numerical Operators
Built-in Functions f l o a t ( x ) c o n v e r t x t o f l o a t i n t ( x ) c o n v e r t x t o i n t e g e r s t r ( x ) c o n v e r t x t o s t r i n g s e t ( x ) c o n v e r t x t o s e t t y p e ( x ) r e t u r n s t y p e o f x l e n ( x ) r e t u r n s l e n g t h o f x m a x ( x ) r e t u r n s m a x i m u m o f x m i n ( x ) r e t u r n s m i n i m u m o f x s u m ( x ) r e t u r n s s u m o f v a l u e s i n x s o r t e d ( x ) r e t u r n s s o r t e d l i s t r o u n d ( x , d ) r e t u r n s x r o u n d e d t o d p r i n t ( x ) p r i n t o b j e c t x Loops w h i l e c o n d i t i o n : < c o d e > f o r v a r i n l i s t : < c o d e > C o n t r o l s t a t e m e n t s : b r e a k t e r m i n a t e l o o p c o n t i n u e j u m p t o n e x t i t e r a t i o n p a s s d o e s n o t h i n g Functions d e f N a m e ( p a r a m 1 , p a r a m 2 = v a l ) : < c o d e >
r e t u r n < d a t a > Reading and Writing Files f h = o p e n ( < p a t h > , ’ r ’ ) f o r l i n e i n f h : < c o d e > f h. c l o s e ( ) o u t = o p e n ( < p a t h > , ’ w ’ ) o u t. w r i t e ( < s t r > ) o u t. c l o s e ( ) Regular Expressions i m p o r t r e p = r e. c o m p i l e ( p a t t e r n ) c o m p i l e s e a r c h q u e r y p. s e a r c h ( t e x t ) s e a r c h f o r a l l m a t c h e s p. s u b ( s u b , t e x t ) s u b s t i t u t e m a t c h w i t h s u b
. a n y o n e c h a r a c t e r