training Day2
PYTHON LANGUAGE
Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python is often described as a "batteries included" language due to its comprehensive standard library.
Program using while loop in python to find factorial of a number
i = int(input("Enter number for factorial"))
fact = 1
while i >= 1
fact = fact*i
i = i-1
print(fact)
LIST[ ] :- It is collection which is ordered and changeable. It allows duplicate members.
TUPLE( ) :- It is collection which is ordered and unchangeable. It allows duplicate members.
SET { } :- It is collection which is unordered and unindexed. It does not allow any duplicate member.
DICTIONARY {Key : value} :- It is a collection which is unordered, changeable and indexed. It does not allow duplicate members.
LISTS
Example :
fruits = [Banana, Cherries, Mango]
for x in fruits : # where x is any variable
print(x)
output :
Banana
Cherries
Mango
Note :- For loop is used for lists, tuples, set, Dictionary.
Python is case-sensitive language.
Here in program if we want to
Check length of list, use function : print(len(fruits))
Add new item to list, use function : append
Example : fruits.append(itemname)
To insert item at any place, use function : insert
Example : fruits.insert(index,"itemname")
To remove any item, use function : remove
Example : fruits.remove(itemname)
To remove any item from end, use function : pop
Example : fruits.pop()
To delete any item from list, use function : del
Example : del.fruits[0]
Note :- If there is no index mentioned, it will delete the complete list,
To copy elements in new list, can be explained :
Example : new_fruits = fruits.copy()
Or
Example : new_fruits = list(fuits).
Comments
Post a Comment