- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10784 Articles for Python
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Python provides gethostname(), gethostbyname() two function. gethostname() retrives the standard host name for the local machine. gethostbyname() retrives host information corresponding to a host name from a host database. Socket. gethostname() Socket. gethostbyname() Algorithm Step 1: use module socket. Step 2: use gethostname() retrives the standard host name for the local machine. Step 3: use gethostbyname() retrives host information corresponding to a host name from a host database. Example Code # Display hostname andIP address import socket def host_IP(): try: hname = socket.gethostname() ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
First convert number into binary using bin() function. Then skip the first two character of binary representation because bin() appends 0b as a prefix in a binary representation of the number and reverse the remaining part. From also character and reverse it till second last character from left. Convert a reversed binary string into integer. Algorithm integernumber(n, bit_size) /* n is the number and bit_size is the bitsize */ Step 1: first convert number into binary . Step 2: skip the first two characters of binary representation string and reverse. Step 3: remaining string and then append 0’s ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
631 Views
Here we use different python inbuilt function. First we use bin() for converting number into it’s binary for, then reverse the binary form of string and compare with originals, if match then palindrome otherwise not. Example Input: 5 Output: palindrome Explanation Binary representation of 5 is 101 Reverse it and result is 101, then compare and its match with originals. So its palindrome Algorithm Palindromenumber(n) /* n is the number */ Step 1: input n Step 2: convert n into binary form. Step 3: skip the first two characters of a string. Step 4: them reverse the ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
398 Views
Given the number, find length of the longest consecutive 1's in its binary representation. Example Input: n = 15 Output: 4 The binary representation of 14 is 1111. Algorithm Step 1: input the number. Step 2: use one counter variable c=0. Step 3: Count the number of iterations to reach i = 0. Step 4: This operation reduces length of every sequence of 1s by one. Example code # Python program to find # length of the longest # consecutive 1s in # binary representation of a number. def maxlength(n): # ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
4K+ Views
Here we use different python inbuilt function. First we use split().split the words into a list. Then traverse till the second last word and upper() function is used for print first character in capital and then add the last word which is title of a name and here we use title(), title function converts the first alphabet to capital. Example Input Pradip Chandra Sarkar Output P.C Sarkar Algorithm fullname(str1) /* str1 is a string */ Step 1: first we split the string into a list. Step 2: newspace is initialized by a space(“”) Step 3: then traverse ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
21K+ Views
In this program we create a user input list and the elements are mixture of odd and even elements. Our task is to split these list into two list. One contains odd number of element and another is even number of elements. Example Input: [1, 2, 3, 4, 5, 9, 8, 6] Output Even lists: [2, 4, 8, 6] Odd lists: [1, 3, 5, 9] Algorithm Step 1 : create a user input list. Step 2 : take two empty list one for odd and another for even. Step 3 : then traverse each element in the ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
817 Views
Given two strings, our task is to print the longest common sub-string. We will solve problem in python using SequenceMatcher.find_longest_match () method. Class difflib.SequenceMatcher is a flexible class for comparing pairs of sequences of any type, so long as the sequence elements are hashable. find_longest_match(a, x, b, y) Find longest matching block in a[a:x] and b[b:y]. Examples Input: str1 = "pythonprogramming", str2 = "pro" Output: pro Algorithm Step 1: Enter two string. Step 2: initialize SequenceMatcher object with the input string. Step 3: find the match ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
15K+ Views
In python is very easy to find out maximum, minimum element and their position also. Python provides different inbuilt function. min() is used for find out minimum value in an array, max() is used for find out maximum value in an array. index() is used for finding the index of the element. Algorithm maxminposition(A, n) /* A is a user input list and n is the size of the list.*/ Step 1: use inbuilt function for finding the position of minimum element. A.index(min(A)) Step 2: use inbuilt ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
753 Views
is and equals(==) operators are mostly same but they are not same. is operator defines if both the variables point to the same object whereas the == sign checks if the values for the two variables are the same. Example Code # Python program to # illustrate the # difference between # == and is operator # [] is an empty list list1 = [] list2 = [] list3=list1 if (list1 == list2): print("True") else: print("False") if (list1 is list2): print("True") else: print("False") if (list1 is list3): print("True") else: print("False") Output True False True
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
74 Views
Given a 26 letter character set, here we are using a new character set. And another character set just like alphabet set (a, b, c........z), then our task is to make a relation between new character set and that alphabet set. Example New character set: qwertyuiopasdfghjklzxcvbnm Input: "wwmm" Output: bbzy Algorithm Step 1: Given a new character set and input the string to make a relation. Step 2: and the original character set also given below. Step 3: Create a dictionary, we use here map technique, we map the English character set and new given character set, ... Read More