Regular Expression!! ^ Matches the beginning of a line $ Matches the end of the line . Matches any character \s Matches whitespace \S Matches any non-whitespace character * Repeats a character zero or more times *? Repeats a character zero or more times (non-greedy) + Repeats a character one or more times +? Repeats a character one or more times (non-greedy) [aeiou] Matches a single character in the listed set [^XYZ] Matches a single character not in the listed set [a-z0-9] The set of characters can include a range ( Indicates where string extraction is to start ) Indicates where string extraction is to end
Posts
Showing posts from 2020
- Get link
- X
- Other Apps
Type Conversion In Python, it's impossible to complete certain operations due to the types involved. For instance, you can't add two strings containing the numbers 2 and 3 together to produce the integer 5, as the operation will be performed on strings, making the result '23'. The solution to this is type conversion . In that example, you would use the int function . Type Conversion !! Another example of type conversion is turning user input (which is a string ) to numbers ( integers or floats ), to allow for the performance of calculations. >>> float (input("Enter a number: ")) + float (input("Enter another number: ")) Enter a number: 40 Enter another number: 2 42.0 Passing non- integer or float values will cause an error. >>> "2" + "3" '23' >>> int ("2") + int ("3") 5 In Python, the types we have used so far have been integers , floats , and strings ....
- Get link
- X
- Other Apps
Strings If you want to use text in Python, you have to use a string . A string is created by entering text between two single or double quotation marks . When the Python console displays a string , it generally uses single quotes. The delimiter used for a string doesn't affect how it behaves in any way. >>> "Python is fun!" 'Python is fun!' >>> 'Always look on the bright side of life' 'Always look on the bright side of life' Newlines !! Python provides an easy way to avoid manually writing "\n" to escape newlines in a string . Create a string with three sets of quotes , and newlines that are created by pressing Enter are automatically escaped for you. >>> """ Customer: Good morning. Owner: Good morning, Sir. Welcome to the National Cheese Emporium. """ 'Customer: Good morning. \n Owner: Good morning, Sir. Welcome to the National Cheese Emporium.' There is a...
- Get link
- X
- Other Apps
Exponentiation !! Besides addition, subtraction, multiplication, and division, Python also supports exponentiation , which is the raising of one number to the power of another. This operation is performed using two asterisks. >>> 2**5 32 >>> 9 ** (1/2) 3.0 Quotient & Remainder !! To determine the quotient and remainder of a division, use the floor division and modulo operators, respectively. Floor division is done using two forward slashes. The modulo operator is carried out with a percent symbol (%). These operators can be used with both floats and integers. This code shows that 6 goes into 20 three times, and the remainder when 1.25 is divided by 0.5 is 0.25. >>> 20 // 6 3 >>> 1.25 % 0.5 0.25 In the example above, 20 % 6 will return 2, because 3*6+2 is equal to 20. You can chain exponentiations together. In other words, you can rise a number to multiple powers...
- Get link
- X
- Other Apps
Floats Floats are used in Python to represent numbers that aren't integers. Some examples of numbers that are represented as floats are 0.5 and -7.8237591. They can be created directly by entering a number with a decimal point, or by using operations such as division on integers. Extra zeros at the number's end are ignored. >>> 3/4 0.75 >>> 9.8765000 9.8765 Floats As you saw previously, dividing any two integers produces a float . A float is also produced by running an operation on two floats, or on a float and an integer . >>> 8 / 2 4.0 >>> 6 * 7.0 42.0 >>> 4 + 1.65 5.65 A float can be added to an integer , because Python silently converts the integer to a float . However, this implicit conversion is the exception rather the rule in Python - usually you have to convert values manually if you want to operate on them. Computers can't sto...
- Get link
- X
- Other Apps
Simple Operations Python has the capability of carrying out calculations. Enter a calculation directly into the Python console, and it will output the answer. >>> 2 + 2 4 >>> 5 + 4 - 3 6 Simple Operations The minus sign indicates a negative number. Operations are performed on negative numbers, just as they are on positive ones. >>> -7 -7 >>> (-7 + 2) * (-4) 20 Python also carries out multiplication and division, using an asterisk to indicate multiplication and a forward slash to indicate division. Use parentheses to determine which operations are performed first. >>> 2 * (3 + 4) 14 >>> 10 / 2 5.0 Using a single slash to divide numbers produces a decimal (or float , as it is called in programming). We'll have more about floats in a later lesson. The spaces around the plus and minus signs here are optional (the code would work without them), b...
- Get link
- X
- Other Apps
Printing Text !! The print statement can also be used to output multiple lines of text. For Example: >>> print('Hello world!') Hello world! >>> print('Hello world!') Hello world! >>> print('Spam and eggs...') Spam and eggs... Try It Yourself Python code often contains references to the comedy group Monty Python . This is why the words, "spam" and "eggs" are often used as placeholder variables in Python where "foo" and "bar" would be used in other programming languages.
- Get link
- X
- Other Apps
Welcome to Python! The three major versions of Python are 1.x, 2.x and 3.x. These are subdivided into minor versions, such as 2.7 and 3.3. Code written for Python 3.x is guaranteed to work in all future versions. Both Python Version 2.x and 3.x are used currently. This course covers Python 3.x , but it isn't hard to change from one version to another. Python has several different implementations, written in various languages. The version used in this course, CPython , is the most popular by far. An interpreter is a program that runs scripts written in an interpreted language such as Python. Welcome to Python! Python is a high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence. It is very popular and used by organizations such as Google, NASA, the CIA, and Disney. Python is processed at runtime by the interpreter . There is no need to com...
- Get link
- X
- Other Apps
Assiggnment 2.3: 2.3 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking or bad user data. Answers: # This first line is provided for you hrs = float(input("Enter Hours:")) rate = float(input("Enter rate per hour:")) result=hrs*rate print("Pay: "+str(result)) Input: Enter hours 35 Enter rate 2.75 Output: pay 96.25 Here is the link: https://www.py4e.com/tools/pythonauto/?PHPSESSID=f1d224f157347bc1c56913b098f5cd2f
- Get link
- X
- Other Apps
Assignment 2.2: 2.2 Write a program that uses input to prompt a user for their name and then welcomes them. Note that input will pop up a dialog box. Enter Sarah in the pop-up box when you are prompted so your output will match the desired output. Answer: # The code below almost works name = input("Enter your name") print("Hello"+" "+name) input: Sarah output: Hello Sarah Here is the link: https://www.py4e.com/tools/pythonauto/?PHPSESSID=b59178881b02435bc1b57d8bd385ca95
- Get link
- X
- Other Apps
Here I am trying to store some basic python programming techniques which will help me to build a model in future!! After installing python 2 or python 3 everyone try to check their python command shell by writing a simple code.. Here it is, print "hello world!" --for python 2 print("hello world") -- for python 3 or we can write print('hello world') To indicate a string in python programming we can use both "" or ' ' .