0% found this document useful (0 votes)
10 views

Python Keywords

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Keywords

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Python Comments:-

In Python, comments are used to provide explanations. Comments are ignored


by the Python interpreter and serve as notes for developers or anyone reading
the code. There are two main types of comments in Python:
Single-line Comments:
Single-line comments begin with the # symbol and continue until the end of the
line. They are typically used for short explanations or comments on a single
line.

# This is a single-line comment


variable = 42 # This is another comment on the same line

Multi-line (or Block) Comments:

In Python, multi-line comments are not supported using a dedicated syntax like
in some other programming languages. However, developers often use triple-
quoted strings (single or double) as a workaround to create multi-line
comments. Since these strings are not assigned to any variable, they act as
comments.

'''
This is a
multi-line comment
using triple-quotes.
'''

OR
"""
Another way to create
a multi-line comment.
"""

Python Data Types:-

Python supports several built-in data types that are fundamental to


programming. Here are some of the most common data types in
Python:
1. Numeric Types:
 int: Integer type, e.g., 5, -3, 1000.
 float: Floating-point type, e.g., 3.14, -0.5, 2e-3.
2. Boolean Type:
 bool: Boolean type, representing True or False.
3. Sequence Types(Container Types):
 str: String type, representing text, e.g., "Hello, World!".
 list: List type, an ordered and mutable collection, e.g., [1,
2, 3].
 tuple: Tuple type, an ordered and immutable collection,
e.g., (1, 2, 3).
4. Set Types:
 set: Set type, an unordered collection of unique elements,
e.g., {1, 2, 3}.
5. Mapping Type:
 dict: Dictionary type, a collection of key-value pairs, e.g.,
{'name': 'John', 'age': 30}.
6. None Type:
 NoneType: The type of the None object, representing the
absence of a value or a null value.
These data types can be used to store and manipulate different kinds
of data in Python programs

Integer DataType:-
In practice, integers are the most commonly used numeric type in
real-life applications. They are widely used for counting odd and even
numbers, tallying monetary values, and similar tasks. For instance, the
following code shows the addition of two integer values:
x=2+3
print(x)
# Output: 5

Decimal Type:-
Decimal numbers are an important data type in Python, with a wide
range of applications in everyday life. They are commonly used in
scientific calculations, as well as in calculations involving weights,
lengths, times, and financial transactions.
x=1.2*3.6
print(x)
# Output: 4.32
x=0.2*4
print(x)
# Output: 0.8

String Type :-
In Python, strings are a fundamental data type used to represent text.
They can contain any character that Python supports and can be
written using single quotes, double quotes, or triple quotes.

Python Keywords:-

In Python, keywords are reserved words that have special meanings and cannot
be used as identifiers (variable names, function names, etc.). These keywords
define the syntax and structure of the language. Here is a list of Python
keywords: Currently there are 36 keywords in python
These keywords serve specific purposes within the
language:
 Logical Operations:
 and, or, not
 Control Flow:
 if, else, elif, while, for, break, continue, pass,
return, yield
 Exception Handling:
 try, except, finally, raise
 Function and Class Definitions:
 def, class
 Importing Modules:
 import, from, as
 Namespace Operations:
 global, nonlocal
 Boolean Values:
 True, False, None

You might also like