Beruflich Dokumente
Kultur Dokumente
CHAPTER – 2
COMPUTER FUNDAMENTALS
1. What is Python?
Python is a popular programming language. It was created in 1991 by Guido van Rossum.
● int
● float
● complex
Variables of numeric types are created when you assign a value to them:
1
Code x =1 # int
y = 2.8 # float
z = 1j # complex
print(type(x))
print(type(y))
print(type(z))
<class 'int'>
Output
<class 'float'>
<class 'complex'>
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume). Rules for Python variables:
There may be times when you want to specify a type on to a variable. This can be done with
casting. Python is an object-orientated language, and as such it uses classes to define data
types, including its primitive types.
● int() - constructs an integer number from an integer literal, a float literal (by rounding
down to the previous whole number) literal, or a string literal (providing the string
represents a whole number)
● float() - constructs a float number from an integer literal, a float literal or a string literal
(providing the string represents a float or an integer)
● str() - constructs a string from a wide variety of data types, including strings, integer
literals and float literals
Type Example
2
Integers x = int(1) # x will be 1
y = int(2.8) # y will be 2
z = int("3") # z will be 3
Floats x = float(1) # x will be 1.0
y = float(2.8) # y will be 2.8
z = float("3") # z will be 3.0
w = float("4.2") # w will be 4.2
Strings x = str("s1") # x will be 's1'
y = str(2) # y will be '2'
z = str(3.0) # z will be '3.0'
print("Hello, World!")
Single-line comments are created simply by beginning a line with the hash (#) character, and
they are automatically terminated by the end of line.
Multiple lines Comments are used to explain things in more detail – are created by adding a
delimiter (“””) on each end of the comment
.
9. What is IDLE in Python?
IDLE is integrated development environment (IDE) for editing and running Python 2.x or
Python 3 programs. The IDLE GUI (graphical user interface) is automatically installed with the
Python interpreter.
10. Write the difference between Interactive mode and script mode.
3
11. List the Keywords used in Python.
Eg: a=b=c=10
Eg: a,b,c=10,20,30
The first variable assign with first value and second variable with second value
and so on. i.e. a with 10, b with 20 and c with 30.
13. Write a single line statement in python to swap values of x and y. where x having
value 20 and y having value 30.
x,y=y,x
print(x,y)
lvalue: expressions that can come on the lhs(left hand side) of an assignment.
rvalue: expressions that can come on the rhs(right hand side) of an assignment.
4
The literals or the expressions that evaluate a value cannot come on lhs of an assignment
hence they are rvalues but variables names can come on lhs of an assignment, they are
lvalues. Lvalues can come on lhs as well as rhs of an assignment.
15. What are Literals/Values? How many types of literals are available in Python
Literals (often referred to as constant values) are data items that have a fixed value. Python
allows several kinds of literals:
1. String literals
2. Numeric literals
3. Boolean literals
4. Special Literal None
5. Literal Collections
16. Is python case sensitive? What is meant by term case sensitive?
Python is case sensitive. The term case sensitive refers as, it treats upper and lower case
characters differently.
1. Arithmetic Operators
4. Bitwise Operators
5. Assignment Operators
6. Special Operators
7. Indentity Operator
8. Membership Operatorn. The value that the operator operates on is called the
operand.
Unary Operators
+ Unary plus
- Unary minus
~ Bitwise complement
5
not Logical negation
Arithmetic Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder/Modulus
** Exponent(raise to power)
// Floor division
Bitwise operators
& Bitwise AND
^ Bitwise exclusive OR(XOR)
| Bitwise OR
Shift operators
<< shift left
>> shift right
Identity operators
is Is the identity same?
is not Is the identity not same?
Relational operators
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to
Assignment operators
= Assignment
/= Assign quotient
+= Assign sum
*= Assign product
%= Assign remainder
-= Assign difference
**= Assign Exponent
//= Assign Floor division
logical operators
And Logical AND
6
or Logical OR
Membership operators
in Whether variable in sequence
not in Whether variable not in sequence
The statement is not valid because on the left of the equal sign there is more than just a
variable.
Yes
Python variables do not have to be explicitly declared to reserve memory space. The
declaration happens automatically when you assign a value to a variable. The equal sing(=) is
used to assign values to variables.
KUMARI USHA
PGT CS
K V JHARSUGUDA
7
8