Posts

How to Find Matching any Single Char Using Python Re

Image
How to Find Matching any Single Char Using Python Re Python regular expression helps you work with expressions. The short name for it is 're'. The major point to note here is Regular expression offers a parser that can be used to match strings within the text. You can search the file name from the text you know. The best example is We often use simple wildcards while searching for anything on our computer. The most commonly used character for conducting search is asterisk *. So, when you type '*.pdf' it would return all the pdfs available in the location where you are conducting your search. How to use re? You need to import 're', if you want to work with regular expressions. >>> import re How to use [...] to find any single char? To match any single character you can use [….].The following example checks if there is a match with any of the letters: 'l' or 'a' or 'b' import re pattern = r'[lab]' sequence = 'we love py

How to Write List comprehension [For loop] in Python

Image
Write a program to generate list comprehension. One list should contain first 20 odd numbers and another should contain first 20 even numbers. How to Code List Comprehension Python-Best Example Here's logic to write list comprehension #1: List comprehension to print odd numbers lst1 = [x for x in range(40) if x % 2 != 0] print('First 20 Odd Numbers:') print(lst1) #2: List comprehension to print even numbers lst2 = [x for x in range(40) if x % 2 == 0] print('First 20 Even Numbers:') print(lst2) Result: after run the Python scripts First 20 Odd Numbers: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39] First 20 Even Numbers: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]  ** Process exited - Return Code: 0 ** Press Enter to exit terminal Related The real use of Git in Dev Ops

How to Concatenate Strings in Python - Plus and Join

Image
Concatenation of strings in Python is possible by using plus and join method. You can also do it in other ways. But in my point of view, these two are the best methods. What are Strings? In data science, you will have to concatenate strings on many occasions. You can find this concept helpful in your project as well. For example: Stringa='Uncle' Stringb='is' Stringc='Married' I have got data in three strings. Here my interest is I need to read these in a single line. So in this type of scenario, the concept of concatenation is helpful. Best methods to concatenate strings Here are the two best methods. One is you can use plus operator. The other one you can use join method. #1: Using plus operator Stringa='Uncle' Stringb='is' Stringc='Married' print(Stringa + ' ' + Stringb + ' ' + Stringc) Result: Uncle is Married #2: Using the join method with separator. Stringa='Uncle' Stringb='is' Stringc='Married'

Git - Why You Need in DevOps Environment

Image
Git is a tool  It is created by Linus Torvalds, the creator of the Linux system. The tool was created to help Linux developers control the development flow among many developers around the world. It helps to solve conflicts, track the modifications, or even revert the configurations that were working before and stopped working in a new version. To install Git, you can access the following link: https://git-scm.com/download/win The installation process is the same as we did for all Windows applications; it is just Next, Next, and Finish.  After the installation, you will find a new program called Git Bash, which allows you to create your local repos and use the Git commands to create versions of your application. GitFlow Now, when we start working on a project, we have the code files that are already in production, and we cannot work in the main branch, because of the CI/CD pipelines. We need to generate a new version of our software with the complete code. Let's commit the first ve

10 Python Questions Recently Asked in Startup Company

Image
A startup company asked these questions. Though it could be a startup, you can use these for other companies as well. Python is a powerful language. You can use it as scripts, web development, and science applications. The point here is you need to know Core python and its frameworks. 10 Python Questions Below are the questions asked so you can refer quickly. 1) What is PEP8? PEP8 is a set of rules to format Python code for better readability.  Further, you can read  the user guide on PEP8. 2) What is memory management, and explain in detail? Python manages memory automatically - cleaning, allocating, and managing; the detailed mechanism is as follows: In the interview, you need to tell as below: Python manages private heap space and is accessible to the only interpreter.  In heap space, Python stores objects and data structures. The memory allocation is the responsibility of the memory manager  Python heap divides into pools (1 heap=64 pool), and the Pool divides into blocks (256 KB).

Python Decorators: How to Say Answer Quickly

Image
Let's first talk about decorators. You will learn how decorators work and where in your real-world project you can use them.  Python Decorators: How to Say Answer Quickly Decorators are an interesting and useful feature of Python. If you understand decorators well, you can build a lot of magical features without much effort. Python Decorators Decorators are another form of function pointers. They accept a function as an argument, then either wrap the function and return a new function, or modify the inputs or outputs to the function. Python decorators help you add behavior to functions or objects dynamically without changing the function or object behavior. Let's say you have a simple function that converts a passed-in string to uppercase and returns the result. Read:  Hyper-ledge fabric 20 Top Interview Questions def  to_uppercase(text):   """Convert text to uppercase and return to uppercase."""   if   not   isinstance (text,  str ): 

Text File , Binary File and UTF-8 Top differences

Image
Here are the differences between Text file, Binary file, and UTF-8. These would help understanding files correctly for beginners. Text File Text file: Contains plain text characters. When you open a text file in a text editor, it displays human-readable content. The text may not be in a language you know or understand, but you will see mostly normal characters that you can type at any keyboard. Binary File Binary file: Stores information in bytes that aren’t quite so human readable. If you open the binary file in a text editor, it will not be readable. UTF-8 UTF-8 is short for Unicode Transformation Format, 8-bit, and is a standardized way to represent letters and numbers on computers. The original ASCII set of characters, which contains mostly uppercase and lowercase letters, numbers, and punctuation marks, worked okay in the early days of computing.  But when other languages were brought into the mix, these characters were just not enough.  Many standards for dealing with other langu