Fundamentals 21 min read

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

This article provides a comprehensive Python tutorial covering numeric operations, string conversions, built‑in functions, data structures, class and object mechanics, and a variety of standard library tools such as enumeration, file handling, and JSON serialization.

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

This guide walks through fundamental Python concepts with clear examples.

Numbers : absolute value ( abs(-6)), base conversions ( bin(10), oct(9), hex(15)), ASCII ↔ integer ( chr(65), ord('A')), logical checks ( all([1,0,3,6]), any([0,0,0,[]])), boolean casting, complex numbers, division with remainder ( divmod(10,3)), floating‑point conversion, rounding, exponentiation, and chained comparisons.

Strings : converting to bytes ( bytes(s, encoding='utf-8')), any object to string ( str(i)), compiling and executing code strings ( compile(...), exec(r)), evaluating expressions ( eval('1 + 3 + 5')), and advanced formatting with format specifications.

Functions : using sorted with custom keys, sum with optional start value, defining functions with positional, keyword, default, *args, and **kwargs parameters, lambda expressions, and creating callable objects via __call__.

Data Structures : creating dictionaries in several ways, immutable sets ( frozenset), regular sets, slices and slice objects for reusable slicing, tuples, and converting lists to sets.

Classes and Objects : checking callability ( callable(obj)), custom __repr__, making instances callable with __call__, using classmethod, dynamic attribute deletion ( delattr), introspection with dir, getattr, hasattr, identity ( id), type checking ( isinstance, issubclass), property creation via property decorator, and understanding metaclasses ( type).

Tools : enumeration ( enumerate), memory size ( sys.getsizeof), filtering ( filter), hashing ( hash), help documentation ( help), file I/O ( open(...).read()), range generation, reversed iteration, zip aggregation, chained operations, and object serialization to JSON using json.dump with a custom lambda to serialize object attributes.

Overall, the article serves as a practical reference for Python developers to master core language features and standard library utilities.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Pythonserializationbasicsdata-structures
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

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.