Python Basic Types and Common Operations
This article provides a comprehensive overview of Python's fundamental data types—including int, float, str, list, dict, set, and tuple—and details common operations, methods, built‑in functions, and file handling techniques essential for mastering basic Python programming.
Python Basic Types and Common Operations
Python’s core built‑in types are introduced, covering integers ( int ), floating‑point numbers ( float ), strings ( str ), lists ( list ), dictionaries ( dict ), sets ( set ) and tuples ( tuple ). The article explains when each type is mutable or immutable and why mastering these four mutable types (str, list, dict, set) enables flexible programming.
String Operations
Common string checks such as a in b , a not in b , and identity tests ( a is b ) are described, followed by a collection of useful string methods (e.g., a.endswith('d') , a.isalpha() , a.lower() , a.upper() , a.swapcase() , a.capitalize() , a.title() ) and manipulation techniques like strip , lstrip , rstrip , join , replace , and translate . Searching and splitting functions ( find , rfind , index , count , split , partition ) are also covered.
List Operations
List manipulation methods are listed: append , insert , extend for adding elements; del , pop , remove , clear for deletion; element assignment via indexing; searching with index and counting with count ; sorting with sort and the built‑in sorted ; reversing ( reverse ) and copying ( copy ).
Dictionary Operations
Dictionary methods such as clear , copy , fromkeys , get , membership test ( key in dict ), items , keys , setdefault , update , values , pop , and popitem are presented.
Set Operations
Set creation and mutation methods are illustrated with visual examples (images omitted), distinguishing operations that return new sets from those that modify the original set in place.
Built‑in Functions and Object Utilities
Common built‑ins for type conversion ( bool , str , int , float , complex , list , tuple , set , dict , enumerate ), object inspection ( type , isinstance , issubclass , id , len , dir ), and functional utilities ( all , any , map , filter , zip , range , sorted , reversed ) are summarized.
File I/O
File handling is explained with the open function signature, mode options, buffering, encoding, and newline handling. Attributes of file objects ( f.closed , f.mode , f.name , etc.) and common operations ( f.read , f.readline , f.readlines , f.write , f.writelines , f.seek , f.tell , f.flush , f.close ) are detailed, including notes on binary vs. text modes.
Additional Topics
The article also touches on mathematical functions ( abs , round , divmod , pow , max , min , sum ), iterator utilities, byte‑array handling, and code compilation/execution functions ( compile , eval , exec , input , print ).
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.