Category: Python tutorial
-
Python tuple data type
Introduction Tuples are one of the most commonly used data structures in Python, especially when you want to represent fixed, read-only data. While they look very similar to lists, their behavior is quite different in one crucial aspect. Lists allow modification, but tuples do not. This difference creates meaningful changes in how Python stores tuples…
-
Understanding List Data Type
What is a List? A list in Python is a collection data type that allows you to store multiple values in a single variable. These values can be of any type: integers, strings, floats, booleans, or even other lists. When Should You Use a List? Use a list when: List Characteristics Feature Description Ordered Yes.…
-
Understanding Immutability in Python’s Fundamental Data Types
In this tutorial, we will explore a foundational and powerful concept in Python programming: immutability, especially with respect to fundamental data types. This topic is essential for understanding how Python manages memory, variable assignment, and object behavior. Fundamental Data Types Before diving into immutability, let’s first recall the fundamental (primitive) data types in Python: All…
-
Python Typecasting
In our previous sessions, we explored Python’s fundamental data types including int, float, complex, bool, and str. Now, let’s move on to the concept of typecasting—a crucial topic when working with different data types in Python. What is Typecasting? Typecasting (also called type conversion or type coercion) is the process of converting a value from…
-
Strings in Python
In Python, a string is essentially a sequence of characters. Unlike some other programming languages (like Java) that have a separate char data type for single characters, Python treats even a single character enclosed in quotes as a string. 1. Representing Strings: Single vs. Double Quotes Python offers flexibility in how you define strings: Both…
-
Python bool Data Type
In Python, bool (short for Boolean) is a built-in data type used to represent truth values: True and False. Booleans are essential in control flow, comparisons, and logical operations. 1. What is a Boolean? Booleans are one of the simplest types in Python. There are only two Boolean values: These values are case-sensitive, so true…
-
Complex Data Type in Python
1. What is a Complex Data Type? In Python, a complex number is a built-in data type that is specifically used for mathematical and scientific computations. A complex number consists of a real part and an imaginary part, just like in algebra. Don’t be misled by the word “complex” — it refers to the mathematical…
-
Addition(+) and multiplication(*) operators with string in Python
Python allows for the use of the addition (+) operator and multiplication (*) operator on strings. In this tutorial, we’ll see how to use these operators with string in Python. Addition(+) operator with string Adding two strings is known as concatenation. Concatenation of two strings creates a string by adding the second string to the…
-
Slicing String in Python
Slicing is used to obtain a sub-string from a given string by slicing it from a given start and end. Here start and end mean the index within a given string. There is another optional parameter step which indicates the increment between each index for slicing. There are two ways to slice a Python string:…
-
Strings in Python
Textual data in Python in represented by string objects. Strings are immutable sequences of unicode code points. Strings in Python can be written in three ways: 1. Single quotes Single quoted strings allows embedded double quotes. Single quoted strings do not span multiple lines. 2. Double quotes Double quoted strings allow embedded single quotes. Double…
