Some Basic Python String Programs-2

Some Basic Python String Programs

Python Program to split a string into groups of n consecutive characters string = “Beta Python: Python for U” n = 5 split_string = [(string[ch:ch+n]) for ch in range(0, len(string), n)] #list comprehension print(split_string) #Output: [‘Beta ‘, ‘Pytho’, ‘n: Py’, ‘thon ‘, ‘for U’] List comprehension is a compact method that defines a list and … Read more

Some Basic Python List Programs-2

Some Basic List Programs

Python program to copy a list list1 = [9, 4, 10, 5] list2 = list(list1) print(“Original list: “,list1) print(“Copied list: “,list2) #Output: Original list: [9, 4, 10, 5] Copied list: [9, 4, 10, 5] The list() built-in method takes an iterable and creates a new list of its elements. Python program to concatenate multiple lists … Read more

What is indexing, iterating and enumerating in python?

What is indexing, iterating and enumerating in python?

Indexing “Indexing” means addressing an element of a sequential object by its position within the sequential object.  A sequential object is in general, an ordered collection. In python, every element of an ordered collection is accessed based on their position in the collection. An index is a numerical form of position. Python uses square bracket … Read more

Sorting in python

Sorting in python

Sorting in python Sorting means arranging a large number of values in a specific order such as ascending and descending, alphabetical, distance, etc. Python provides built-in functions that offer powerful features to do basic sorting or customize ordering at a smooth level. Python has a built-in sort() list method that modifies it in-place and a sorted() … Read more

Set Data Type in Python

Set Data Type in Python

Python Sets Mathematically a set is a collection of elements, not having any particular order. A Python set is an unordered collection of immutable and unique elements. As the set elements are usually not stored in order of appearance in the set, so there is no index attached to any element. Thus they do not … Read more

Some Basic Python String Programs-1

Some Basic Python String Programs-1

String A string is an immutable sequence of  Unicode characters. Unicode includes every character in all languages. Python does not have a character data type, a single character is simply a substring with a length of 1 and can be accessed by using indexing. The string module contains several useful constants and classes, as well … Read more

Some Basic List Programs-1

Some Basic List Programs-1

List List is a changeable and ordered data type that allows it to be indexed and sliced. It can contain heterogeneous values such as integers, floats, strings, tuples, lists, and dictionaries but they are commonly used to store collections of homogeneous objects. Python program to check if a list is empty or not empty_list = … Read more

Some Basic Python Tuple Programs-1

Some basic tuple programs

Tuple A tuple is an immutable and sequential collection of data that can be indexed and sliced. Python tuple can contain homogeneous as well as heterogeneous values of data types such as integers, floats, strings, lists, and dictionaries. Python Program to concatenate multiple tuples tup1 = (7, 1, 9) tup2 = (5, 2, 3, 4, … Read more

Slicing in python

Slicing

Slicing Slicing extracts a subset of elements from a sequence. In python, elements are sliced based on their index in the stream. As a sequence(List, tuple, and string) is an ordered stream of data, it can be indexed and sliced while a collection(Set and dictionary) is an unordered stream of data, thus they can’t be … Read more

Multi-Dimensional List In Python

What is List in Python List is a mutable and sequenced container. It can contain homogeneous objects as well as heterogeneous values such as integers, floats, strings, tuples, lists, and dictionaries. It can be indexed and sliced. A list that has other lists as its element is called the Nested list. Multi-dimensional list A one-dimensional … Read more

%d bloggers like this: