Python - Some Basic Programs for beginners (a simple and quick read)

·

2 min read

I have executed the below programs on GitHub code space:

###String Concatenation
str1="hello"
str2="world"
result=str1+" "+str2
print(result)

 ###String length
str3="welcome"
str4="to Python Club"
result1=str3+" "+str4
length=len(result1)
print("length of the string:",length)

###String lowercase
str5="python is awesome"
uppercase = str5.upper()
lowercase = str5.lower()
print("Uppercase letters are:",uppercase)
print("Lowercase letters are:",lowercase)

###String replace
str6 = "Hardwork pays at the end"
new_text = str6.replace("end","beginning")
print("Modified Text is:",new_text)

###String split
str7 = ("Smartwork beats Hardwork")
new_textwords = str7.split()
print("Splitted Words are:",new_textwords)

###String strip
str8 = ("   We need zero spaces at work")
new_word=str8.strip()
print("The stripped text is:",new_word)

###String substring
str9=("Python seems to be easy")
substring = "seems"
if substring in str9:
    print(substring,"found in the text")

Output of the above are:

@skmak1111 ➜ /workspaces/python $ python test-Day2-sk.py
hello world
length of the string: 22
Uppercase letters are: PYTHON IS AWESOME
Lowercase letters are: python is awesome
Modified Text is: Hardwork pays at the beginning
Splitted Words are: ['Smartwork', 'beats', 'Hardwork']
The stripped text is: We need zero spaces at work
seems found in the text
@skmak1111 ➜ /workspaces/python (main) $

### Float Variables

x = 80.20
y = 20.80

###Basic Arithmetic
##Addition
result = x + y
print("The sum is:",result)

##Subtraction
result1 = x - y
print("The difference is:",result1)

##Multiplication
result2 = x*y
print("The Product is:",result2)

##Division
result3 = x/y
print("The Quotient is:",result3)

##Rounding
result4 = round(3.1456789, 3) # Rounds to 3 decimal places
print("Rounded number is:",result4)

Output for the above is:

@skmak1111 ➜ /workspaces/python $ python test_numeri.py
The sum is: 101.0
The difference is: 59.400000000000006
The Product is: 1668.16
The Quotient is: 3.855769230769231
Rounded number is: 3.146
@skmak1111 ➜ /workspaces/python(main) $

###Integer Varibales

Num1 = 48
Num2 = 22

###Arithmetic Operations

##Addition
result = Num1 + Num2
print("The sum is:", result)

##Subtraction
result1 = Num1 - Num2
print("The difference is:", result1)

###Multiplication
result2 = Num1 * Num2
print("The Producat is:", result2)

###Division
result3 = Num1 / Num2
print("The quotient is:", result3)

###Modulus (Remainder)
result4 = Num1 % Num2
print("Modulus (Remainder):", result4)

###Absolute value
result5 = abs(-9)
print("Absolute value:", result5)

Output for the above is:

@skmak1111 ➜ /workspaces/examples (main) $ python test_numeric.py
The sum is: 70
The difference is: 26
The Producat is: 1056
The quotient is: 2.1818181818181817
Modulus (Remainder): 4
Absolute value: 9