Sie sind auf Seite 1von 8

CLASS- XI COMPUTER SCIENCE

CHAPTER – 2
COMPUTER FUNDAMENTALS

1. What is Python?

Python is a popular programming language. It was created in 1991 by Guido van Rossum.

● Python can be used on a server to create web applications.


● Python can be used alongside software to create workflows.
● Python can connect to database systems. It can also read and modify files.
● Python can be used to handle big data and perform complex mathematics.
● Python can be used for rapid prototyping, or for production-ready software
development.
2. Explain about Python programming.
● Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
● Python has a simple syntax similar to the English language.
● Python has syntax that allows developers to write programs with fewer lines than
some other programming languages.
● Python runs on an interpreter system, meaning that code can be executed as soon as
it is written. This means that prototyping can be very quick.
● Python can be treated in a procedural way, an object-orientated way or a functional
way.
3. Explain how Python Syntax differ from other programming languages.
● Python was designed to for readability, and has some similarities to the English
language with influence from mathematics.
● Python uses new lines to complete a command, as opposed to other programming
languages which often use semicolons or parentheses.
● Python relies on indentation, using whitespace, to define scope; such as the scope of
loops, functions and classes. Other programming languages often use curly-brackets
for this purpose.
4. Explain Numeric types used in Python with example.

There are three numeric types in Python:

● 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'>

5. Explain the rules to define a variable name in Python.

A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume). Rules for Python variables:

● A variable name must start with a letter or the underscore character


● A variable name cannot start with a number
● A variable name can only contain alpha-numeric characters and underscores (A-z, 0-
9, and _ )
● Variable names are case-sensitive (age, Age and AGE are three different variables)

6. Explain Type Casting in Python with example.

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.

Casting in python is therefore done using constructor functions:

● 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'

7. Write a simple Print Statement to print Hello, World! in Python

print("Hello, World!")

8. Explain how to define comments in Python Programming.

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.

Python has two basic modes: script and interactive.


The normal mode is the mode where the scripted and finished .py files are run in the
Python interpreter.
Interactive mode is a command line shell which gives immediate feedback for each
statement, while running previously fed statements in active memory. As new lines are fed
into the interpreter, the fed program is evaluated both in part and in whole.
Interactive mode is a good way to play around and try variations on syntax.

3
11. List the Keywords used in Python.

False class finally is break return assert

None continue for lambda except try import

True def from nonlocal in while pass

and del global not raise with

as elif if or else yield

12. Explain Multiple Assignments in Python

1. Assigning same value to multiple variables:

You can assign a same value to multiple variable in a single statement

Eg: a=b=c=10

2. Assigning multiple values to multiple variables:

You can assign multiple values to multiple variable in a single line

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)

14. Explain about lvalue and rvalue in python.

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.

Eg: a=20 # correct statement

20=a # wrong statement

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.

17. What are operators in python?


Operators are special symbols in Python that carry out arithmetic or logical computation.
The value that the operator operates on is called the operand.

1. Arithmetic Operators

2. Comparison (Relational) Operators

3. Logical (Boolean) 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

18. Why the statement is not valid? X-1=x.

The statement is not valid because on the left of the equal sign there is more than just a
variable.

19. Name five primitive data types in Python.


1. Numbers
2. Strings
3. List
4. Tuple
5. Dictionary.
20. Is string a sequence type data type?

Yes

21. How can we declare variables in Python?

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.

22. What do you mean by None data type in Python ?


Ans. None is a special data type. It means non existent or not known or empty.It is a unique
value that may be used where it is required but there is no obvious value.

KUMARI USHA
PGT CS
K V JHARSUGUDA

7
8

Das könnte Ihnen auch gefallen