Posts

Showing posts from December, 2024

Functions in Python

Image
Document Home HG Blogs Functions The functions in python can be defined as the reusable block of codes that perform a certain task. Before we start defining functions ourselves, we’ll look at some of Python’s built-in functions. Let’s start with the most well-known built-in function, called print: >>> print('Hello, readers!') Hello, readers! >>> print(15) 15 Creating python functions In programming language there are certain syntax we need to follow and python is not an exception def function_name: #statements return Advantages of using functions Advantages of using functions A Python function can be defined once and used many times. So it aids in code reuse: you ...

Sets in python

Image
Document Home HG Blogs SETS Sets are an ideal choice for representing a group of unique values as a single entity. They offer several key characteristics: they do not allow duplicate elements, they do not preserve the order of insertion, and they do not support indexing or slicing. While the order of elements may not be guaranteed, sets can be sorted for specific purposes. This makes sets useful for tasks like removing duplicates from a list or performing set operations like union, intersection, and difference. s={10,20,30,40} print(s) Ouput:{10,20,30,40} Important set functions add(x): When we want to add individual element to the set we use add() ex...

List and Tuple in Python

Image
Document Home HG Blogs List A list is a data type in Python used to store a collection of items. Lists are mutable, which means we can modify their contents after they are created.The data in the list is stored in the square brackets. lst = [1,2,3,4,5] Accessing the elements of the list The elemnts of the list can be accessed by two methods By Indexing By Slice Operator Indexing lst = [1,2,3,4] print(lst.[0]) output:1 Slice operator list = list1[start:stop:step] start ==>it indicates the index where slice has to sta...

Strings and String Operations In Python

Image
Document Home HG Blogs Strings The string is defined as any set of characters within either single quote or the double quotes. ex: s='Notes' s="Notes" HOW TO ACESS CHARCTERS OF THE STRING There are two ways to access the characters in the string By Indexing By Slice Operator Indexing s = "Notes" print(s[0]) Output:N print(s[1]) Output:o print(s[2]) Output:t print(s[3]) Output:e print(s[4]) Output:s Slice Operators Syntax: s[begin:end:step] Begin: From where the we have to consider the slicing of the string End: From where the slicing of the string will ...