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

Ch-6[Python Fundamentals]

The document covers fundamental concepts of Python, including the IPO cycle, tokens, keywords, identifiers, literals, operators, and functions. It explains various data types, error handling, and input/output operations in Python. Additionally, it discusses variable creation, assignment, and the differences between static and dynamic typing.

Uploaded by

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

Ch-6[Python Fundamentals]

The document covers fundamental concepts of Python, including the IPO cycle, tokens, keywords, identifiers, literals, operators, and functions. It explains various data types, error handling, and input/output operations in Python. Additionally, it discusses variable creation, assignment, and the differences between static and dynamic typing.

Uploaded by

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

Unit-I[Computer System Organization]

Ch-6[Python Fundamentals]

1. What is IPO cycle?


Ans. The IPO (Input-Process-Output) cycle
represents the sequence of operations in a
computer system.
1. Input: Data is entered into the system.
2. Process: The system processes the data
based on programmed instructions.
3. Output: The processed information is
displayed as the result.
2. What are tokens in Python?
Ans.In Python, tokens are the smallest units of a
program that have meaning. They include:
1. Keywords: Reserved words with specific
meanings (e.g., if, else, while).
2. Identifiers: Names for variables, functions,
and objects.
3. Literals: Constants (e.g., numbers, strings).
4. Operators: Symbols that perform
operations (e.g., +, -, *).
5. Punctuation: Symbols that organize code
structure (e.g., :, ;, ,).
3. What are keywords in Python?
Ans. In Python, keywords are reserved words that
have special meanings and cannot be used as
identifiers (variable names, function names, etc.).
Examples include:
1. if: Used for conditional statements.
2. while: Used for loop constructs.

3. def: Used to define functions.


4. class: Used to define classes.
4. What are identifiers in Python?
Ans. Identifiers in Python are names used to
identify variables, functions, classes, modules, or
other objects. They must start with a letter or an
underscore and can include letters, digits, and
underscores. Identifiers are case-sensitive.
5. What are literals in Python?
Ans. Literals in Python are fixed values assigned to
variables or constants. They represent data such
as strings, numbers, boolean values (True, False),
and the special None value. These literals are
directly assigned to variables.
6. What are string literals in Python?
Ans. String literals in Python represent sequences
of characters enclosed within single (') or double
(") quotes. For example, "Hello" and 'World' are
string literals.
7. What are escape sequences? Mention
some common escape sequences.
Ans. Escape sequences are special characters in
string literals that perform specific actions.
Common ones include \n (newline), \t (tab), \\
(backslash), \' (single quote), and \" (double quote).
8. What are single line strings?
Ans. Single line strings in Python are string literals
that are written in a single line and enclosed within
single (') or double (") quotes. For example, "Hello,
World!".
9. What are multiline strings?
Ans. Multiline strings in Python are string literals
that span multiple lines, enclosed within triple
quotes (''' or """). They preserve line breaks and
whitespace.

10. What are numerical literals?


Ans. Numerical literals in Python represent
numeric values and include integer literals,
floating-point literals, and complex literals. For
example, 42, 3.14, and 1 + 2j.
11. What are integer literals?
Ans. Integer literals in Python represent whole
numbers without fractional parts. They can be
written in decimal (e.g., 42), binary (e.g.,
0b101010), octal (e.g., 0o52), or hexadecimal
(e.g., 0x2A).
12. What are float point literals?
Ans. Floating-point literals in Python represent real
numbers with fractional parts, written in decimal
notation (e.g., 3.14) or scientific notation (e.g.,
1.23e4).
13. What is complex type?
Ans. The complex type in Python represents
complex numbers, consisting of a real part and an
imaginary part. Complex literals are written as a +
bj, where a is the real part and b is the imaginary
part. For example, 3 + 4j.
14. What is Boolean literal?
Ans. Boolean literals in Python represent truth
values and are True and False. They are used in
conditional expressions and logical operations.
15. What is special literal?
Ans. The special literal in Python is None,
representing the absence of a value or a null value.
It is often used to indicate that a variable has no
value assigned to it.
16. What are operators and operands?
Ans. Operators in Python are symbols that perform
operations on variables and values (operands). For
example, in the expression a + b, + is the operator
and a, b are the operands.

17. What are unary operators?


Ans. Unary operators in Python operate on a single
operand. Common unary operators include the
negation operator (-) and the logical not operator
(not).
18. What are binary operators? Mention its
types.
Ans. Binary operators in Python operate on two
operands. Types include:
 Arithmetic: +, -, *, /, //, %
 Comparison: ==, !=, <, >, <=, >=
 Logical: and, or
 Bitwise: &, |, ^, ~, <<, >>
19. What are punctuators?
Ans. Punctuators in Python are symbols that
structure and organize code. They include
characters like :, ;, ,, (), {}, [], and ..
20. What are expressions?
Ans. Expressions in Python are combinations of
values, variables, operators, and function calls that
are evaluated to produce a result. For example, 3
+ 4, len("hello"), and a * b.
21. What are comments?
Ans. Comments in Python are non-executable lines
that provide explanations or notes within the code.
They are created using the # symbol. For example,
# This is a comment.
22. What are functions?
Ans. Functions in Python are reusable blocks of
code designed to perform a specific task. They are
defined using the def keyword followed by the
function name and parentheses.

23. What are statements?


Ans. Statements in Python are individual
instructions that the interpreter can execute.
Examples include assignment statements, print
statements, and function calls. For instance, x = 5
is an assignment statement.
24. What are blocks and indentations?
Ans. Blocks in Python are groups of statements
that execute together. Indentation (using spaces or
tabs) defines the boundaries of a block. Proper
indentation is crucial for code structure and
readability.
25. What is physical line?
Ans. A physical line in Python is a single line of
code as it appears in the source file. Each physical
line ends with a newline character.
26. What is logical line?
Ans. A logical line in Python is a meaningful
instruction that the interpreter executes. Multiple
physical lines can be combined into one logical line
using backslashes (\) or by using parentheses,
brackets, or braces.
27. What is docstring?
Ans. A docstring in Python is a special string literal
used to document functions, classes, and modules.
It is enclosed in triple quotes (""") and appears
immediately after the definition.
28. What is a variable?
Ans. A variable in Python is a named location in
memory that stores data. It holds values that can
change during program execution.
29. How can a variable be created?
Ans. A variable is created by assigning a value to it
using the assignment operator (=). For example, x
= 10 creates a variable x with the value 10.

30. "Variables are not storage container in


Python"-explain.
Ans.In Python, variables are references to objects,
not storage containers. When a variable is
assigned a value, it points to the object in memory
rather than containing the value itself.
31. Define Lvalues and Rvalues.
Ans. Lvalues (Left values) refer to locations that
can hold values, such as variables. Rvalues (Right
values) refer to the actual data values. In the
assignment x = 5, x is an Lvalue, and 5 is an
Rvalue.
32. What is an assignment and how it is
done in Python?
Ans. Assignment in Python associates a value with
a variable using the assignment operator (=). For
example, x = 10 assigns the value 10 to the
variable x.
33. How is variable definition important in
Python?
Ans. Variable definition is important because it
allocates memory for the variable and establishes
its identity. Proper definition ensures that variables
are correctly recognized and used in the program.
34. Define name error.
Ans. A NameError in Python occurs when the code
attempts to access a variable or function name
that has not been defined. For example, print(x)
without defining x first.
35. Define static typing.
Ans. Static typing refers to a type system where
variable types are explicitly declared and checked
at compile-time. Languages like Java and C++ use
static typing.

36. Define dynamic typing.


Ans. Dynamic typing refers to a type system where
variable types are determined at runtime, and
types can change. Python uses dynamic typing,
allowing flexibility in variable usage.
37. Define type error.
Ans. A TypeError in Python occurs when an
operation or function is applied to an object of an
inappropriate type. For example, adding a string
and an integer ("hello" + 5) results in a TypeError.
38. What are simple input and output?
Ans. Simple input in Python is obtained using the
input() function, which reads user input as a string.
Simple output is done using the print() function,
which displays data to the console.
39. What are the possible errors when
reading numerical values?
Ans. Possible errors when reading numerical values
include ValueError (if the input cannot be
converted to the desired numeric type) and
EOFError (if the input stream is closed
unexpectedly).
40. How to print output through print()
function?
Ans. The print() function in Python displays output
to the console. It can print strings, variables, and
expressions. For example, print("Hello, World!")
prints the string to the console.
41. What are features of print() function?
Ans. The print() function in Python can:
 Print multiple items separated by commas.
 Use the sep parameter to change the separator
between items.
 Use the end parameter to change the end
character (default is newline).
 Support formatted string literals (f-strings).

You might also like