IDENTFIERS
In Python, identifiers are names given to entities like variables, functions, classes, modules, etc. Here are the rules and conventions for identifiers in Python:
2. Valid Examples:
3. Invalid Examples:
4. Python Keywords:
5. Convention for Identifiers:
6. Special Identifiers:
=============================================================
RESERVED WORDS
In Python, reserved keywords are predefined words that have special meanings and purposes within the language. These keywords cannot be used as identifiers (names for variables, functions, classes, etc.) because they are reserved for specific syntactical and operational purposes. Here is a list of Python's reserved keywords as of the latest versions:
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
These keywords are case-sensitive, meaning False is different from false or FALSE
How Keywords are Used:
Importance of Keywords:
Understanding and respecting these keywords is crucial because attempting to use them as identifiers will result in syntax errors or unexpected behavior in your Python programs. They are fundamental to Python's syntax and provide essential building blocks for creating structured and efficient code.
Version Specifics:
The set of keywords can vary slightly depending on the Python version, although the core set tends to remain stable across most recent versions. Always refer to the official Python documentation or use Python's keyword module to get an updated and accurate list of keywords for your specific Python version.
============================================================
DATA TYPES
n Python, data types represent the type or category of data that variables or values can hold. Python is dynamically typed, meaning you don't need to explicitly declare the data type of a variable when you create it; the interpreter assigns it dynamically based on the value assigned.
Python contains following inbuilt data types.
1) INT
2) Float
3) Complex
4)Bool
5) Str
6) Bytes
7) Bytearray
8) Range
9) List
10) Tuple
11) Set
12) Frozenset
13) Dict
14) None
领英推荐
Note: Pyhton contains several inbuilt functions
1) Type() - To check the type of variable
2)ID() - To get address of object
3) Print()- To print the value
Overall I would say in python everything is object.
Numeric Types:
Sequence Types:
Mapping Type:
Set Types:
Boolean Type:
None Type:
Slicing of Strings
n Python, slicing is a technique used to extract a subset of elements from a sequence like strings, lists, tuples, etc.
Syntax:
The syntax for slicing a string s is s[start:end:step]:
Key Points:
Explanation of Examples:
Explanation of Examples:
s[0:5]: Starts from index 0 and ends at index 5-1=4, giving "Hello".
s[7:]: Starts from index 7 and goes till the end of the string, giving "World!".
s[:5]: Starts from the beginning and ends at index 5-1=4, giving "Hello".
s[:]: Copies the entire string.
Negative Indices:
s[-6:-1]: Starts 6 characters from the end and ends 1 character from the end, giving "World".
s[-6:]: Starts 6 characters from the end and goes till the end, giving "World!".
Step Size:
Reverse the String:
Notes:
Type Conversion:
Python also supports type conversion (or casting) between different data types using functions like int(), float(), str(), list(), tuple(), dict(), set(), etc., allowing you to change the type of a variable or value as needed.
=============================================================
-
Co-founder & Chief Operating Officer at CYBERINFOMINES TECHNOLOGY PVT. LTD.
1 个月Nice docs, It could be more better if we keep some real time use case to explain topic in better ways. Thank you ??