Anda di halaman 1dari 7

COMPUTER

SCIENCE
HOLIDAY
HOMEWORK
MADE BY – ANSH VOHRA
CLASS- XII-A
ROLL-03
PROGRAMMING LANGUAGE – PYTHON
SUBJECT TEACHER- DEEPTI MA’AM
QUES. WHAT IS PYTHON?
ANS. Python is a widely used general-purpose, high level programming
language. It was initially designed by Guido van Rossum in 1991 and
developed by Python Software Foundation. It was mainly developed for
emphasis on code readability, and its syntax allows programmers to
express concepts in fewer lines of code.
PYTHON BASIC DATA TYPES ARE SHOWN BELOW WITH SOME
EXAMPLES USING SOURCE CODE.

1. STRINGS:-
Strings are arrays of bytes representing Unicode characters.
However, Python does not have a character data type, a
single character is simply a string with a length of 1. Square
brackets can be used to access elements of the string.
FOR EXAMPLE:

String1 = "I'm Ansh"


print("string with the use of Double Quotes: ")
print(String1)

2. LIST:-
Lists are just like the arrays, declared in other languages. Lists
need not be homogeneous always which makes it a most
powerful tool in Python. A single list may contain Data Types
like Integers, Strings, as well as Objects. Lists are also very
useful for implementing stacks and queues. Lists are mutable,
and hence, the data could be altered even after creation of list.
FOR EXAMPLE:
List = []
print("Initial blank List: ")
print(List)
3. TUPLES:-
Tuple is a collection of Python objects much like a list. The
sequence of values stored in a tuple can be of any type, and
they are indexed by integers. The important difference between
a list and a tuple is that tuples are immutable. Also, Tuples are
hashable whereas lists are not. Values of a tuple are
syntactically separated by ‘commas’. Although it is not
necessary, it is more common to define a tuple by closing the
sequence of values in parentheses. This helps in understanding
the Python tuples more easily.
FOR EXAMPLE:

Tuple1 = (0, 1, 2, 3)
Tuple2 = ('python', 'computer')
Tuple3 = (Tuple1, Tuple2)
print("\nTuple with nested tuples: ")
print(Tuple3)

4. DICTIONARY:-
Dictionary in Python is an unordered collection of data
values, used to store data values like a map, which unlike
other Data Types that hold only single value as an element,
Dictionary holds key: value pair. Key value is provided in the
dictionary to make it more optimized. Each key-value pair in a
Dictionary is separated by a colon: whereas each key is
separated by a ‘comma’.
FOR EXAMPLE:

Dict = {1: 'Geeks', 2: 'For', 3: 'Geeks'}


print("Dictionary with the use of Integer Keys: ")
print(Dict)
5. OPERATORS:-
There are basically three types of operators which we can use
in the basic code.
a. ARITHMETIC OPERATOR
b. LOIGICAL OPERATOR
c. COMPARISION OPERATOR

Arithmetic Operator: - Arithmetic Operators perform various


arithmetic calculations like addition, subtraction, multiplication,
division, %modulus, exponent, etc. There are various methods for
arithmetic calculation in Python like you can use the eval function,
declare variable & calculate, or call functions.
x=4
y=5
print(x+y)
**The output of the above code is shown below
(4+5=9)-> Process In compiler
>>>9 -> Actual output
NOTE: - Similarly we can use various mathematical operators like
(+,-, /,*, %) -> also called as arithmetic operators in python programs
Logical Operator: - Logical operators in Python are used for
conditional statements are true or false. Logical operators in Python
are AND, OR and NOT. For logical operators following condition are
applied.

 For AND operator – It returns TRUE if both the operands (right


side and left side) are true
 For OR operator- It returns TRUE if either of the operand (right
side or left side) is true
 For NOT operator- returns TRUE if operand is false
a = true
b = false
print(“a and b is”, a and b)
print(“a or b is ”, a or b)
print(“not a is”, not a)

Comparison Operator: - These operators compare the values on


either side of the operand and determine the relation between them. It
is also referred as relational operators. Various comparison operators
are ( ==, != , <>, >,<=, etc.)
x=4
y=5
print(‘x>y is ’, x>y)
Explanation of the code given above----
->For comparison operators we will compare the value of x to the value of y and
print the result in true or false. Here in example, our value of x = 4 which is smaller
than y = 5, so when we print the value as x>y, it actually compares the value of x to
y and since it is not correct, it returns false.

6. FUNCTIONS:-
A function is a set of statements that take inputs, do some
specific computation and produces output. The idea is to put
some commonly or repeatedly done task together and make a
function, so that instead of writing the same code again and
again for different inputs, we can call the function.
Python provides built-in functions like print(), etc. but we can
also create your own functions. These functions are called
user-defined function
Def evenOdd( x ):
if (x % 2 == 0):
print ("even")
else:
print ("odd")

*The output would be

>>>Even
>>>odd

MADE BY ANSH VOHRA


CLASS XII-A (PCM)
ROLL - 03

Anda mungkin juga menyukai