You are on page 1of 16

Python Full Stack Developer Interview Questions

Continued……

Data Types in Python

1. Number :

In python, in number data type we have 3 types those are Integer, Float
and Complex they are explained as follows:

In Python, the number data type is used to represent numerical values. There are
primarily three types of numerical data types in Python:

1. Integer (int): Integers represent whole numbers without any fractional


part. They can be positive, negative, or zero.

2. Floating-point (float): Floating-point numbers represent real numbers


with a decimal point or an exponent notation.
3. Complex (complex): Complex numbers are represented by a real part
and an imaginary part. They are written in the form a + bj, where a is the
real part, b is the imaginary part, and j is the imaginary unit (√-1).

Python provides built-in functions and operators to work with numeric data
types. Here are some common operations:

• Arithmetic operations: Addition (+), subtraction (-), multiplication (*),


division (/), exponentiation (**), floor division (//), and modulus (%).
• Comparison operations: Greater than (>), less than (<), equal to (==), not
equal to (!=), greater than or equal to (>=), and less than or equal to (<=).
• Type conversion functions: int(), float(), and complex() to convert
values between different numeric types.
2. String Data Type in Python:

In Python, the string data type (str) is used to represent sequences of characters.
Strings are immutable, meaning they cannot be modified after creation. They
are one of the most commonly used data types in Python and are used to store
textual data.

Strings can be created using single quotes (') or double quotes ("). Both are
equivalent, and you can choose either based on your preference or to handle
situations where one type of quote is embedded within the string.

Python also supports triple-quoted strings (''' or """) which can span multiple
lines. These are often used for docstrings (documentation strings) or for
representing multiline text.
Strings are versatile and extensively used in Python programming for tasks such
as text processing, data manipulation, input/output handling, and more.
Positive Indexing starts from 0 from right-hand-side and Negative Indexing
starts from -1 from left-hand-side

Methods of Strings Data Type in Python:

The string data type (str) in Python comes with a variety of built-in methods
that allow you to manipulate, search, and transform strings. Here are some
commonly used string methods in Python:

1. Conversion Methods:
• capitalize(): Returns a copy of the string with the first character
capitalized and the rest lowercase.
• upper(): Returns a copy of the string with all characters converted
to uppercase.
• lower(): Returns a copy of the string with all characters converted
to lowercase.
• swapcase(): Returns a copy of the string with uppercase characters
converted to lowercase and vice versa.
• title(): Returns a copy of the string with the first character of each
word capitalized.

2. String Manipulation Methods:


• strip(): Returns a copy of the string with leading and trailing
whitespace removed.
• lstrip(): Returns a copy of the string with leading whitespace
removed.
• rstrip(): Returns a copy of the string with trailing whitespace
removed.
• replace(old, new): Returns a copy of the string with occurrences
of old replaced by new.
• join(iterable): Concatenates the elements of an iterable (e.g., list)
with the string as a separator.
• split(sep=None, maxsplit=-1): Splits the string into a list of
substrings using the specified separator (default is whitespace).
• startswith(prefix): Returns True if the string starts with the
specified prefix, otherwise False.
• endswith(suffix): Returns True if the string ends with the
specified suffix, otherwise False.

3. String Searching and Counting Methods:


• find(sub[, start[, end]]): Returns the lowest index of the substring
sub within the string, or -1 if not found.
• rfind(sub[, start[, end]]): Returns the highest index of the
substring sub within the string, or -1 if not found.
• count(sub[, start[, end]]): Returns the number of occurrences of
the substring sub in the string.

4. String Formatting Methods:


• format(*args, **kwargs): Formats the string using placeholders
{} and optional format specifiers.
• format_map(mapping): Formats the string using a mapping of
keys to values.

5. String Testing Methods:


• isalpha(): Returns True if all characters in the string are
alphabetic, otherwise False.
• isdigit(): Returns True if all characters in the string are digits,
otherwise False.
• isalnum(): Returns True if all characters in the string are
alphanumeric (letters or digits), otherwise False.
• isspace(): Returns True if all characters in the string are
whitespace, otherwise False.

These are just some of the most commonly used string methods in Python.
There are many more available for various purposes. You can explore these
methods and their detailed usage in the Python documentation or experiment
with them interactively in the Python interpreter or in your favorite IDE.

3. List :

In Python, a list is a built-in data type used to store a collection of items.


Lists are ordered, mutable (modifiable), and can contain elements of
different data types, including other lists. Lists are defined using square
brackets [ ] and elements are separated by commas. Here's an example of
a list:
4. Tuples:

In Python, a tuple is a built-in data type similar to a list, but with a few
key differences. Like lists, tuples are used to store collections of items,
but unlike lists, tuples are immutable, meaning their elements cannot be
changed after creation. Tuples are defined using parentheses () and
elements are separated by commas. Here's an example of a tuple:
Methods of List Data type in Python
Methods of Tuples data type in Python
Sets Data Type in Python:
In Python, a set is a built-in data type used to store unique elements. Sets are
unordered collections of distinct objects, meaning each element appears only
once in the set. Sets are defined using curly braces {} or the set() constructor,
with elements separated by commas. Here's an example of a set:

Some key characteristics and operations associated with sets include:

1. Unordered: Sets do not maintain any specific order of elements.


2. Uniqueness: Sets cannot contain duplicate elements. If you attempt to
add a duplicate element, it will be ignored.
3. Mutable: Sets are mutable, meaning you can add or remove elements
from them.
4. Membership Testing: You can quickly test whether an element is
present in a set using the in keyword.
5. Set Operations: Sets support various mathematical operations such as
union, intersection, difference, and symmetric difference.
6. No Indexing: Sets do not support indexing or slicing because they are
unordered collections.

Here are some common methods and operations associated with sets:
Dictionary Data Type in Python

In Python, a dictionary is a built-in data type used to store collections of key-


value pairs. Dictionaries are unordered, mutable, and can contain elements of
different data types. Each element in a dictionary is accessed by its key rather
than by an index, providing a convenient way to store and retrieve data based on
meaningful labels. Dictionaries are defined using curly braces {} and elements
are separated by commas, with each element consisting of a key-value pair
separated by a colon :. Here's an example of a dictionary:

Some key characteristics and operations associated with dictionaries include:


1. Key-Value Pairs: Each element in a dictionary consists of a key and its
corresponding value.
2. Keys: Keys in a dictionary must be unique and immutable, meaning they
cannot be changed after creation. Common key types include strings,
numbers, and tuples.
3. Values: Values in a dictionary can be of any data type and can be duplicated.
4. Accessing Elements: Elements in a dictionary are accessed by specifying their
key inside square brackets [] or using the get() method. If the specified key is
not found, it raises a KeyError or returns a default value if provided.
5. Adding and Modifying Elements: You can add new key-value pairs to a
dictionary or modify existing ones by assigning a value to a specific key.
6. Removing Elements: You can remove elements from a dictionary using the
del keyword, the pop() method, or the popitem() method.
7. Length: You can find the number of key-value pairs in a dictionary using the
len() function.
8. Iteration: You can iterate over the keys, values, or key-value pairs of a
dictionary using loops.
9. Dictionary Methods: Python provides several built-in methods for working
with dictionaries, such as keys(), values(), items(), update(), clear(), etc.
Dictionaries are widely used in Python for tasks such as representing mappings,
storing configurations, and organizing data efficiently.

You might also like