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

Python Basics: Features, Operators, and Methods

Uploaded by

aarinbanerjee5
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)
17 views2 pages

Python Basics: Features, Operators, and Methods

Uploaded by

aarinbanerjee5
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 Theory

Assignment1

Assignment Date: 22.10.24 and submission date: 25.10.24

1. State and explain any six features of python.

2. State any six applications of python.

3. State any six reasons, why you must consider writing software applications in Python.

4. Explain input command in python with suitable example.

5. Explain print command in python with suitable example.

6. State which of the following python statements are valid and invalid.

a. print("ksk", + "123")

b. print("ksk" '+' "123")

c. print("ksk", '+', "123")

d. print('ABC is a "technological" University')

e. print(2 + '3')

f. print('2' * 3)

7. What will be the output of following print statements?

a. print('abc' * 2)

b. print(3+4j + 2+1j)

c. print(3*2 // 4)

8. What are the types of following variables?

a. a = 55

b. b = ‘3 + 4j’

c. c = “1DBATU”

d. d = 5 + 2j

e. e = a

f. f = b+c

9. Explain any six arithmetic operators of python with suitable examples of each.

10. Explain any six assignment operators of python with suitable examples of each.

11. Explain all comparison operators of python with suitable examples of each.

12. Explain “and, or, not” operators of python with suitable examples of each.

13. Explain all bitwise operators of python with suitable examples of each.
14. Explain while loop with suitable example?

15. Differentiate between List, Tuple & Set with suitable examples of each.

16. Explain any three collection data types of Python with suitable examples of each.

17. Explain append() and copy() methods of list with suitable examples of each.

18. Explain count() and index() methods of list with suitable examples of each.

19. Explain insert() and remove() methods of list with suitable examples of each.

20. Explain reverse() and remove() methods of list with suitable examples of each.

21. Explain clear() and extend() methods of list with suitable examples of each.

22. Explain pop() and sort() methods of list with suitable examples of each.

23. What will be the output of following python statements?

a. print(23 // 5)

b. print(2 << 2)

c. print(2 >> 0)

d. print(2 ^ 2)

e. print(2 != 2)

f. print(2 < 0)

Common questions

Powered by AI

Python's bitwise operators perform operations on integers at the binary level . '&' computes a binary AND, where bits present in both operands are set; e.g., '5 & 3' results in '1' . The '|' does an OR, setting bits present in either operand; e.g., '5 | 3' results in '7' . '^' computes XOR where bits are set if only one operand has the bit; e.g., '5 ^ 3' results in '6' . These are useful for low-level data manipulation and efficient computations in competitive programming .

Python's 'and' operator returns True if both operands are true; it's used in conditional checks requiring multiple truths, e.g., 'a and b' where both must evaluate to True . The 'or' operator returns True if at least one operand is true, useful in conditions where multiple alternatives may suffice . 'Not' inverts a boolean value, turning True to False and vice versa, ideal for negating conditions . These enable complex conditional logic in code .

Python is an interpreted language which improves productivity as it doesn't require compilation . It has a clear and readable syntax with a design philosophy that emphasizes code readability . Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming . It is dynamically typed, reducing the need to declare variable types explicitly . Python has a comprehensive standard library that supports many common programming tasks . It's also maintained by a large community, providing extensive support and a rich ecosystem of libraries and frameworks .

The input command in Python is used to read a string from the user's input; for example, input('Enter a number: ') waits for the user to type something and press enter . The print command outputs data to the screen; for example, print('Hello, World!') directly outputs the text to the console . This makes Python suitable for interactive programs where user input is needed .

In Python, the '+' operator performs string concatenation or arithmetic addition based on operand types. For strings, '+' concatenates; e.g., 'hello' + 'world' results in 'helloworld' . For numbers, it adds values; e.g., 2 + 3 results in 5 . This operator's flexibility allows seamless combinations of primitive data manipulation with intuitive syntax .

Python is widely used in web development frameworks like Django and Flask due to its capabilities in handling internet protocols and data streams . It's also prominent in scientific and numeric computing, using libraries such as NumPy and SciPy which enhance its mathematical computation capabilities . Python is a popular choice for artificial intelligence and machine learning, with libraries like TensorFlow and PyTorch facilitating these domains . It is used for software development, as a support language, for automation and script writing . Its simple syntax and high-level data structures make it effective for rapid application development . In education, Python is favored for teaching programming due to its simplicity and readability .

Lists in Python are mutable and ordered, allowing elements to be changed after creation; e.g., myList = [1, 2, 3] allows for append operations . Tuples are ordered and immutable, ensuring data integrity and faster performance; e.g., myTuple = (1, 2, 3) cannot be altered after definition . Sets are unordered and mutable, allowing for unique element storage and fast membership tests; e.g., mySet = {1, 2, 3} supports operations like union and intersection . The choice depends on the need for mutability, the necessity of order, and the requirement for unique data entries .

Python offers simplicity in syntax which results in improved productivity and ease of learning for new programmers . It is open-source, providing cost efficiency and accessibility . The extensive standard library supports a wide variety of programming tasks, reducing dependency on external resources . Python's compatibility with major platforms and systems makes it versatile for development . It supports multiple programming paradigms, enhancing its flexibility . Python's large community ensures robust support and a wealth of resources, fostering continuous development and improvement .

Python's floor division '//' operator divides two numbers and rounds down to the nearest whole number; e.g., '23 // 5' results in '4' . The bitwise shift operators, '<<' and '>>', shift bits in a binary representation left or right; '2 << 2' results in '8', multiplying by four (shift left adds zeros on the right), and '2 >> 0' outputs '2', as no shift occurs . These operators enable both high-precision calculations and efficient bit manipulation .

Python's dynamic typing means variable types are determined during runtime, enhancing flexibility but potentially leading to runtime errors if incorrect type assumptions are made . For example, 'a = 55' declares 'a' as an integer, but assigning a string later would not cause an error until used improperly . While dynamic typing aids in fast prototyping and enhanced productivity, it requires careful management of type usage to avoid logical errors .

You might also like