0% found this document useful (0 votes)
10 views2 pages

Python Fundamentals Overview

Uploaded by

Utkarsh Bhayni7f
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Python Fundamentals Overview

Uploaded by

Utkarsh Bhayni7f
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PYTHON FUNDAMENTALS

WORKSHEET
1. What are literals in Python? How many types of literals are there in Python?
2. How string literal is represented in Python?
3. What is a statement and expression?
4. What is the role of indention in Python?
5. What are variables?
6. What is dynamic typing in python?
7. Differentiate keyword and identifier.
8. What are tokens in Python?
9. What will be the output of following? a=20
b=a+1
a=33
print(a+b)
10. What is wrong with following code fragment? a=20
print(a)
b=33
print(b)
11. What is wrong with following code fragment? name="freya"
classs=4
print(name+classs)
12. What will be the output of following python code? a,b=3,4
a,b,c=b,a+3,b-1
print(a,b,c)
13. What will be the output of following python code? a,b=3,4
c,a=b*4,a+
4
print(a,b,c)
14. What will be the output of following python code/code fragment?
a. print(print("vishal"))

b. print("visha
l")
print("india
n")

c. print("vishal",end
=" ")
print("indian")

d. a=int(input("enter first no"))


b=int(input("enter second no"))
a,b=b,a

print("a=",a)

print("b=",b)
#if user is entering 5 and then 10
15. Write a Python program to find out the simple interest.
16. Write a Python program to find out the compound interest.
17. Write a Python program to find out the area of the triangle.
18. Write a Python program to find out the circumference of circle.
19. Write a Python program to find out the area of the circle.
20. Write a Python program to convert Celsius to Fahrenheit.
21. Write a Python program to reverse a three digit number.
22. Write a Python program to find out the sum of a three digit number.
23. Write a python to display all of keywords supported by Python.
24. Which of the following is an invalid statement?
a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
25. What is the error of following code : a,b=100?
26. Differentiate block/code block/suite?
27. How comments are given in Python program?

Common questions

Powered by AI

Dynamic typing in Python allows variables to be assigned without declaring their type, and the type is automatically inferred at runtime. This flexibility allows for more generic code and fewer lines of code than static typing, where types are explicitly declared. Dynamic typing can improve development speed but may introduce runtime errors that aren't caught at compile time, unlike in static typing languages .

Listing Python keywords using a program (e.g., via `keyword.kwlist`) provides a reference point to ensure that identifiers are not mistakenly assigned these reserved names, which would lead to syntax errors. This listing aids debugging by confirming valid identifiers and optimizing code by adhering to Python's syntax rules. It also helps in writing clearer, more maintainable code by ensuring proper variable usage .

In Python, tokens are the smallest units within a program, including keywords, identifiers, literals, and operators. The Python interpreter reads the program and breaks it down into tokens, which is the first step in interpreting the Python code. Understanding tokens is crucial for parsing, syntax analysis, and helps diagnose syntax errors. The token system allows Python to understand and execute code correctly .

The code fragment encounters a TypeError due to an attempt to concatenate a string (`name`) and an integer (`classs`) using the '+' operator. To resolve this, the integer needs to be converted to a string using `str(classs)` before concatenation: `print(name + str(classs))` .

The code snippet initializes `a` and `b` with 3 and 4, respectively. The expression `a,b,c=b,a+3,b-1` reassigns `a` to 4, `b` to 6 (3+3), and `c` to 3 (4-1). The updated values are therefore a=4, b=6, c=3. This demonstrates tuple unpacking and simultaneous assignment in Python .

The given code snippet has no syntactical error and will execute normally, printing 20 and 33 for variables `a` and `b` respectively. If there's an error mentioned, it likely relates to an external context not defined in the snippet, such as a missing variable assignment before these lines were executed .

Keywords are reserved words in Python that have special meanings and are part of the syntax rules, such as 'if', 'else', 'while'. They cannot be used as identifiers, which are names given to entities like variables, functions, and objects. Confusing a keyword with an identifier can result in syntax errors because keywords cannot be used to name identifiers .

In Python, expressions are constructs that can be evaluated to produce a value, whereas statements are units of code that perform an action. Expressions are used in contexts that return values, allowing them to be used inside functions or as arguments. Statements can include control structures like loops or conditionals. They dictate the flow of execution, but not all statements return values. This distinction is crucial for structuring programs and optimizing their functional execution .

Indentation is crucial in Python as it indicates blocks of code, replacing the need for braces that other languages use to denote blocks. Improper indentation can lead to 'IndentationError' and can alter the control flow, causing logical errors in the program that might not immediately be obvious .

In Python, literals are constants used to denote fixed values. They differ by data types, such as strings, numerics (int, float), booleans, and special ones like None. String literals are enclosed in quotes, numeric ones can be simple numbers, boolean literals are True or False, and None is a special literal. This distinction is significant because it affects how data is stored and manipulated within programs .

You might also like