Python Notes
Python Notes
features supported
List identity by Python
operators in python.
Defind class and object Q5)List file operations in Python.
1. Simple and easy to learn: Python has a clean and . Class.
1)In Python, a class is aitblueprint or template Opening file (using open() function) "is" operator: It returns True if two variables point to
simple syntax that makes easy to read and write Object.
for
code,creating
even forobjects.
beginners.It defines a set of Reading file (using read() function) the same object in memory.
Method.
attributes
2. Dynamicallyandtyped:
methods
Python that will be present
is dynamically typed,in Writing file (using write() function)
Inheritance.
whichobject
each means created
that you don't
from need to declare
the class. variable
Classes are Copy files For example:python
Polymorphism.
types
used tobefore
createusing them.
new data This makes
types coding
that can faster
be used Delete files (using remove() function)
and easier, but it can also lead to some errors. Data Abstraction. a = [1, 2, 3]
throughout a program. Closing file (Using close() function)
3. Interpreted: Python code is interpreted at Encapsulation. b=a
2)An object is an instance of a class. It is
runtime, which means that you can run your code
created from the blueprint defined by the
Describe Python Interpreter print(a is b) # Output: True
without having to compile it first. This makes it a Q6)Describe indentation
The Python interpreterin is
Python.
available on most operating systems, including Windows, macOS, and Linux.
class. Each object created from
good choice for rapid prototyping and testing.a class has its
own set of attributes andsupports
methods. The It can be installed as a standalone2.application
"is not"oroperator:
as part ofIta larger
returnsdevelopment
True if twoenvironment,
variables dosuch
notas
4. Object-oriented: Python object-oriented Indentation refers to the spaces at the
attributes are(OOP),
programming specific
whichto allows
that instance of the
you to create Anaconda or Visual Studio Code.
beginning of a code line. Python point to the same object in memory. For example:
reusable
class andcode
caninbethe form of objects.
different from the attributes Q)Write Python code for finding greatest
indentation refers to adding white 2. a =among [1, 2, 3]four numbers .
5.
of Portable: Pythoncreated
code canfrom be runtheonsame
manyclass. list1 = [ ] num = int(input("Enter number of3.elements
other objects
different platforms, including Windows, macOS, space before a statement to a particular b = [1,in2, 3]
Q10)How to others.
give single and multiline list: ")) for i in range(1, num + 1): element =
4. print(a is not b) # Output: True
Linux, and many block of code. In another word, all the
comment in python.
6. High-level: Python is a high-level language, which int(input("Enter
statements with the same elements:
space to"))the list1.append(element)
means that it
in Python, youabstracts
can use away
themany of the low-level
# character to print("Largest
right, belong element
to the same codeis:", max(list1)) Output:
block
details of
create programming,
a single-line making itAnything
comment. easier to write
after Enter number of elements in list: 4 Q9)Explain Local and Global variable.
code.
the # character on that line will be ignored by Q7) NameEnterdifferent
elements:modes
10 of
7. Large standard library: Python comes with a large
the interpreter.
standard library thatHere's an example
provides many usefulof atools
single-
and pythonEnter elements: 20 1) A local variable is a variable that is declared within a
line comment
functions : # This
for common is a single-line
programming tasks. Enter elements: 45 function or a block of code. It is only accessible within the
8. Third-party inlibraries: Python has a vast ecosystem 1. Interactive Mode: This
Enter elements: 20is a command-
comment Python scope of the function or block in which it is declared. Local
of third-party libraries that can be easily installed line mode in which
Largest you is:
element can45enter
2)to create a multiline comment in Python, you
and used to extend the functionality of the language. variables are usually used to store temporary values that are
can use triple quotesPython
(''' orhas""") to enclose the PythonQ)Write
commands one bycode
python one and see frequency of each characters in a given file.
to count
9. Strong community: a strong needed for a specific part of the program. Once the function or
comment. Here's an example of a multiline their output
importimmediately. To startpprint
collections import the file_input = input('File Name: ') with open(file_input, 'r') as info:
community of developers who contribute to the block ends, the local variable is destroyed, and its value is no
language and‘’’create useful tools and libraries.
comment: interactive
count mode, simply type `python`
= collections.Counter(info.read().upper()) value = pprint.pformat(count) print(value)
10. Web frameworks: Python has many popular web on the command line. longer accessible.For example:
frameworks, such as Django and Flask, that make it
Q11)Describe Dictionary
easy to build web applications. 2. Script Mode: This is a file-based mode function example() {
in which you can write your Python var x = 10;
A dictionary is a reference book or an console.log(x);
Q2) Describe Tuples in Python. code in a file with a `.py` extension. You
electronic resource that lists words in }
A tuple is a collection of items which can then execute the code by running
alphabetical order and provides theiris ordered
and unchangeable. Tuples are the sequence or the file using the command `python
meanings, definitions, pronunciations, and 2) A global variable, on the other hand, is a variable that is
series values of different types separated by filename.py` in the terminal.
sometimes other relevant information such as declared outside of any function or block of code. It is
commas (,). Example: tup1=(10,20,30)
their origins, usage, synonyms, and antonyms. 3. GUI Mode: This is a graphical user accessible from anywhere in the program, including within
It is a comprehensive resource for interface-based mode in which you can functions. Global variables are usually used to store values that
Q3) Write use of lambda function in
understanding the meaning of words and their need to be accessed and modified from different parts of the
use tools like IDLE, PyCharm, Jupyter
usage in. different contexts.
python
Notebook, or Spyder to write and program.Forexample:
The lambda function, which is also called
execute your Python code. This mode is
anonymous
Q12)Statefunction. A lambda function
use of namespace can
in Python var y = 20;
take any number of arguments, but can only ideal for larger projects or complex data
haveuseoneofexpression. Syntax: lambda analysis tasks.
The namespaces in Python is important function example() {
arguments
to ensure that : expression
variables, functions, and classes Write basis operations of list console.log(y);
Example:
are uniquex=and lambda a,breferenced
can be : a*b Print(x(10,5)
without }
Output: 50
ambiguity. Here are some ways namespaces 1)Accessing values in list:
are used in Python 3)update list example();
Q4) Write syntax of defining class in Tupel list
Python. Tupel
2) Deleting use
Values List use square
in List 4)indexing
Class<ClassName>: paranthesis brackets Q)explain the need for function in python
<statement1> 5)list slicing
Tuples can not List can be changed
<statement2> be changed Functions in Python. You use functions in
. Tuple I programming to bundle a set of instructions that
List is a mutable data
. immutable structure you want to use repeatedly or that, because of their
<StatementN> tuple is more List take more complexity, are better self-contained in a sub-
memory memory than a tupleprogram and called when needed. That means that
effitiant that list a function is a piece of code written to carry out a
Q)Write python program to read
specified task .
contents of abc.txt and write same
content to pqr.txt.
Classes Objects
1)The class is collection 1)An object is an
of data and the instance of class
function are used to
manipulate data
2)The class represent 2)Object represent the
the basis for the object real world entity