How to split a string in python?

wondering how to split a string in python? Python has in-built function split that splits a string. Split Function By default python split function splits string by space and returns list of splitted string. Example str=”Once upon a time” print(str.split(” “)) Output: [“Once”,”upon”,”a”,”time”] Similarly we can pass any separator we want. Example str=”once-upon-a-time” print(str.split(“-“)) Output: […]

How to reverse a string in python?

In certain situation, you may want to reverse the string using Python programming language. Following is the right way to do it. Reverse a string in python In python, there is no in built function available which can reverse a string. However we can use slice in backwards to print the string in the reverse. […]

Python how to check if list contains element?

In python, we can check if a list contains certain element. For this “in” keyword is helpful. Example selected_candidates=[“rahul”,”ajay”,”vijay”] #check if raju is present in the list if “raju” in selected_candidates: print(“Raju has been selected for the job”) else: print(“Raju has been disqualified for the job”) Output: Raju has been disqualified for the job.

Read html file in python beautifulsoup

Beautifulsoup is a powerful library that helps scrape complex to complex html website easily. Python+Requests+Beautifulsoup=Successful Web Scraping Read html file in python beautifulsoup To use beautifulsoup library, this library must be present in the system. If you are using pycharm, then go to file then project settings and install bs4. bs4 contains beautifulsoup library. Following […]

Python How to make a dictionary from two lists?

We have two lists. And we want to create a dictionary combining values of these two lists. In such case, we can create a dictionary from two lists as following way. Example name_list=[“rahul”,”vijay”,”ajay”] phone_list=[“1111″,”2222″,”3333”] #declare an empty dictionary phone_book={} for idnum in range(0,len(name_list)): phone_book.add(name_list[idnum],phone_list[idnum]) #lets print the dictionary print(phone_book) Output: { “rahul”:”1111″, “vijay”:”2222″ “ajay”:”3333″ } […]

Python how to check if string contains substring?

In certain situation, you may want to know whether a sting contains another sub-string. Then the helpful tool that eases the process of knowing this is, “in” keyword. It checks whether the supplied element is present in the target element or not. If element is present then it would return true otherwise it would return […]

How to make python print something multiple times?

Python has print function which prints the passed argument. And in some cases we may want to print a message multiple times. If we want to print something multiple times then for loop is an easy option. for _ in range(0,10): print(“hello friend”) Output: hello friend hello friend hello friend hello friend hello friend hello […]

Check if a python string contains a character

In some cases we may want to check if string contains a certain character. To do check presence of a character in a string in python, we can use the in keyword functionality. If element is present then it would return true other wise it would return false. Example sentence=”Orange is not apple” #lets check […]

Connect MS Access database in python (pyodbc)

MS access is also used as database to store and update data. In python projects we can use ms access as database and for that pyodbc library is required. Install pyodbc library Assuming you have prior known of python and library installation, run the following command in your terminal or command prompt. pip install pyodbc […]

How to select li element in selenium python?

In certain cases we may want to fetch data from list by using Selenium in Python. The simplest solution to target any element by its tag name is to use find_element_by_tag_name. Note: Selenium Python has similar function find_elements_by_tag_name. Do not use this one. It returns a list of targeted element. Select li element in selenium […]

How to launch Internet Explorer IE browser in selenium python?

Assuming you have prior knowledge of Python and Selenium, following are the step by step guideline to launch Internet Explorer browser in Selenium Python. To run internet explorer browser from selenium python, you must have to have internet explorer driver available in your system. You can download it from selenium’s official website. Selenium Official Website: […]

How to add new python interpreter in pycharm?

In mac OS and Linux OS, python older version is pre-installed. So if we run pycharm, then by default pycharm picks older version of python which is 2.7. But we want the latest version 3.0 as interpreter in pycharm. So following is the solution to add new python interpreter in pycharm. Open pycharm and launch […]

How to check if python is already installed?

Mac Operating System and Linux operating system has already python installed. Where as certain application needs python, so such application might have installed python in windows as well. So irrespective of the platform it is best to first check if python is already installed. How to check if Python is installed in windows 10? Open […]