Fundamentals 21 min read

Comprehensive Python Basics: Numbers, Strings, Functions, Data Structures, Classes, and Tools

This article provides a thorough overview of essential Python concepts, covering numeric operations, string manipulation, function definitions, data structures, class and object usage, as well as useful built‑in tools and utilities, illustrated with clear code examples for each topic.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Comprehensive Python Basics: Numbers, Strings, Functions, Data Structures, Classes, and Tools

This guide introduces fundamental Python techniques, starting with numeric operations such as absolute values, base conversions, ASCII handling, logical checks, and arithmetic functions. Example code demonstrates usage of abs(-6) , bin(10) , ord('A') , all([1,0,3]) , and round(10.0222222, 3) .

String handling is covered next, including conversion to bytes, casting objects to strings, executing code strings with compile and exec , evaluating expressions via eval , and advanced formatting using format specifications. Sample snippets show bytes('apple', encoding='utf-8') and "{0:.2f}".format(3.14159) .

The functions section explains built‑in utilities like sorted , sum , and scope modifiers nonlocal and global . It also illustrates creating lambda expressions, custom function signatures with positional, keyword, default, *args, and **kwargs parameters, and using signature from the inspect module.

Data structure examples include creating dictionaries with dict() , immutable sets via frozenset , converting lists to sets, slices with the slice object, and tuples using tuple() . Code shows dict(zip(['a','b'], [1,2])) and list(range(5, -1, -1)) .

Object‑oriented concepts cover checking callability, defining __repr__ , making objects callable with __call__ , using classmethod , dynamic attribute deletion with delattr , introspection via dir , attribute access with getattr , type checking with isinstance and issubclass , and understanding metaclasses where type creates classes. Example class Student demonstrates these features.

The tools section presents utilities such as enumerate , memory size inspection with sys.getsizeof , filtering with filter , hashing via hash , help documentation with help , file I/O using open , range generation, reversed iteration, aggregation with zip , and JSON serialization of objects using json.dump with a custom default=lambda obj: obj.__dict__ function.

PythonprogrammingData StructuresClassesFunctionsfundamentalsutilities
Python Programming Learning Circle
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.