0% found this document useful (0 votes)
97 views5 pages

Python Programming Basics and Concepts

The document provides a comprehensive overview of Python programming, including definitions, features, applications, and basic concepts such as variables, data types, and comments. It explains the use of functions like print() and input(), as well as the significance of tokens and keywords in Python. Additionally, it covers the modes of working in Python and offers examples to illustrate various programming principles.

Uploaded by

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

Python Programming Basics and Concepts

The document provides a comprehensive overview of Python programming, including definitions, features, applications, and basic concepts such as variables, data types, and comments. It explains the use of functions like print() and input(), as well as the significance of tokens and keywords in Python. Additionally, it covers the modes of working in Python and offers examples to illustrate various programming principles.

Uploaded by

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

Python Revision notes

1 What is a computer program?


Ans A computer program is a set of instructions that a
computer follows to complete a task.
2 What is python?
Ans Python is a simple programming language used to
write a computer program. It isa easy to learn
programming language.
3 What are the applications of python?
Ans a) To develop games.
b) Build websites
c) Program robots using AI
d) Perform scientific calculations.
4 What are the features of python?
Ans a) Python is a programmer friendly language.
b) It is easy to learn.
c) Python is a platform independent language.
d) Python is an interpreted language.
e) It is an object oriented programming language.
f) Python is a case sensitive language
5 What are two modes of working in Python?
Ans a) Interactive mode-line by line execution of
command happens. there is no need to save file
while working in interactive mode
b) Script mode-complete program is written first
and then the execution happens. Saving
program is necessary before executing it.
6 What is the use of print() in python?
Ans print() function is used to display the output of any
command on the screen.
For eg. print(‘hello world’) will print hello world on
the output screen
7 What are variables? List rules for naming variables.
Ans Variables are containers for storing data values. A
variable is a named memory location that stores the
data and can be changed during the program
execution.
Rules for naming variables:
a) A variables name can only contain alphabets,
digits, underscore.
b) A variable’s name can be started with an
alphabet/underscore but can’t start with a digit.
c) We cannot use keywords as names of variables
viz print, int, float etc.
8 Multiple assignment of variables?
Ans a) Python allows a single value to be assigned to
multiple variables simultaneously.
Example x=y=z=1
b) We can assign different values to multiple
variables in a single line.
m1,m2,m3=12,15,18

9 Fill in the blanks:


a) Python is a high level programming language.
b) In the python IDLE we type and execute our
code in script area.
c) Executing a python script or code in the python
idle is called interactive mode.
d) A variables name can be started with an
alphabet or underscore.
e) int,print,for,if are examples of keywords.
f) Single line comments in python code are
written using the # sign.
g) Syntax refers to the rules to be followed while
writing a program in any language.
h) In the python code, we use indentation to
define a block of code.
i) In python code 90.87 is an example of float
datatype.
j) ‘\t’ and ‘\n’ are examples of escape sequences.
k) Program elements whose value remains to be
constant during the execution are literals.
l) Is Boolean a basic datatype supported in python
yes
10 What are comments? Explain type of comments in
python.
Ans Comments are used to explain the code. Python
interpreter ignores the comments.
a) Single line comment: they are written using #
(hash) sign.
Example:#this is a comment.
b) Multi-line comment: starts and ends with triple
quotes.
Example:’’’ this is a multiline comment
starts and ends with triple quotes’’’
11 What are tokens in python?
Ans The smallest individual unit in a program is called
token.
Python has following tokens:
a) Keywords
b) Identifiers
c) Literals
d) Operators
12 Define the following:
Ans a) Keyword: Keyword is a predefined word that
gives special meaning to the [Link] are
reserved words which has predefined meaning
to the compiler.
Eg. False, if, True, print, int etc.
b) Identifiers: Identifiers are fundamental building
blocks of a program and are used to name the
programming elements such as user-defined
names, variables, modules and other objects.
c) Literals: Literals also referred to as constant
values are the data items that have a fixed value
like 345,suveer,76.97 etc.
d) Operators: Operators are special symbols used
for carrying out operations on variables and
values. For eg.
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus-it returns remainder as an answer
13 What are datatypes?
Ans The type of data stored in a variable is represented
by a datatype. For example person’s age is
represented as numeric value, name is stored as
string.
int(integer): it can store the integer values that can
be positive or negative like 43,5678,-987654 etc
float: it is used to store floating point values like 7.5,
89.67, -98.765 etc
str(String) : A string datatype represents a string of
characters enclosed within single or double
quotation [Link]. “hello”,”123”,’book’ etc
14 Define input() function.
Ans The input() function is used to take input from the
user instead of assigning a fixed value to a variable.
Input function take input from the user as a string
and then convert it to required datatype.
For eg int(input(‘enter number’)) will convert
entered string into a integer.
15 Give use of following escape sequences:
Ans a) ‘\t’ :gives a tab space between two characters.
b) ‘\n’: this is called as newline character is used to
end a line and start a new line

16 Who invented python?


Ans Guido Van Rossum
17 What is the extension for saving a python file
Ans .py
18 What will be the output of ‘6’*’6’
Ans It will result in an error as 6 is written in single
quotes which is the syntax for writing a string and
strings cannot be multiplied.
19 What will be the output of 6*6
Ans 36

Common questions

Powered by AI

The print() function in Python outputs text to the console, allowing developers to display messages or program results (e.g., print('Hello')). It facilitates debugging and user interaction. The input() function is used to gather user input during program execution, which is received as a string. Developers often convert this string to other data types as needed (e.g., int(input('Enter a number'))) to perform operations with the input data .

Python's platform independence means it can run on various operating systems without changing the source code, due to its reliance on a portable interpreter. This benefit allows developers to write code once and deploy it across different environments, increasing efficiency and reducing the cost and time associated with modifying software for different systems. It enhances Python's versatility, making it suitable for a wide range of applications .

Tokens are the smallest units of a Python program, analogous to words in a sentence. Types of tokens include Keywords (e.g., 'if', 'False'), which have special meaning; Identifiers, which name program elements like variables and functions; Literals, which are fixed values like numbers (345), strings ('text'), and floats (76.97); and Operators, special symbols that perform operations (e.g., + for addition, - for subtraction).

As an object-oriented language, Python facilitates designing solutions around objects, encapsulating data and behavior, and fostering modularity and code reuse. This paradigm enables more natural problem representation via classes and objects, which streamlines development for complex applications. It encourages the use of inheritance and polymorphism to build robust, extensible programs, though it requires a solid understanding of design principles to leverage effectively .

Comments in Python serve to explain the code, making it more readable and maintainable. Single-line comments are initiated with a '#' symbol, making the text following it until the end of the line a comment (e.g., # this is a comment). Multi-line comments are enclosed within triple quotes ''' or """, and can span multiple lines, making them useful for longer explanations or disabling large code sections during testing .

Variable assignment in Python can be done by assigning a single value to multiple variables simultaneously or by assigning different values to multiple variables in a single line (e.g., x=y=z=1 or m1,m2,m3=12,15,18). The naming rules specify that variable names can include alphabets, digits, and underscores, but must not begin with a digit. Additionally, variable names cannot be Python's reserved keywords such as 'print', 'int', or 'if' .

Python's case sensitivity demands that variables and identifiers be matched exactly in letter casing (e.g., 'Variable' and 'variable' would be considered different identifiers). This requirement increases precision in code but can also lead to errors if case mismatches occur inadvertently. Developers must be meticulous with case usage, which promotes disciplined coding practices, though it may also introduce challenges during debugging if such inconsistencies are overlooked .

In Python, interactive mode allows for line-by-line execution, meaning commands can be entered and executed immediately without the need for saving the code. This is useful for experimenting and debugging small code snippets quickly. On the other hand, script mode involves writing the entire program in a file, which must be saved before execution. This mode is beneficial for developing larger applications where complete scripts are written and reused .

Python is considered a high-level programming language because it abstracts complex details of the computer's hardware, allowing developers to focus on coding logic rather than low-level machine specifics. This separation simplifies development, reduces errors, and makes code easier to write and maintain. Being high-level also enhances portability across different platforms, which broadens Python's applications in various technology sectors .

Python is popular due to its programmer-friendly nature and ease of learning. It is platform-independent, meaning it can run on various operating systems without modification. Python is also interpreted, meaning code is executed line-by-line, which simplifies debugging. As an object-oriented programming language, it allows for modular and reusable code. Additionally, Python's case sensitivity makes variable names distinct based on letter casing, which is crucial for coding accuracy and consistency .

You might also like