# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
# Concatenation
string1 = 'Thirty' + ' ' + 'Days' + ' ' + 'Of' + ' ' + 'Python'
string2 = 'Coding' + ' ' + 'For' + ' ' + 'All'
print(string1)
print(string2)
# Variable declaration and printing
company = "Coding For All"
print(company)
# Length of the company string
print(len(company))
# String methods: upper, lower
print(company.upper())
print(company.lower())
# capitalize, title, swapcase
print(company.capitalize())
print(company.title())
print(company.swapcase())
# Slice out the first word
print(company[7:]) # Removes 'Coding '
# Check if it contains a word using index or find
print(company.find("Coding")) # Returns index if found, -1 if not
print("Coding" in company) # Returns True
# Replace 'Coding' with 'Python'
print(company.replace('Coding', 'Python'))
# Replace 'Python for Everyone' to 'Python for All'
print('Python for Everyone'.replace('Everyone', 'All'))
# Split the string
print(company.split()) # Split by space
# Split comma-separated string
tech_companies = "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon"
print(tech_companies.split(', '))
# Character at index 0
print(company[0])
# Last index of the string
print(company[-1])
# Character at index 10
print(company[10])
# Acronym or abbreviation
phrase1 = 'Python For Everyone'
phrase2 = 'Coding For All'
acronym1 = ''.join([word[0] for word in phrase1.split()])
acronym2 = ''.join([word[0] for word in phrase2.split()])
print(acronym1)
print(acronym2)
# Index of first occurrence of characters
print(company.index('C'))
print(company.index('F'))
# rfind to determine the last position of 'l'
print('Coding For All People'.rfind('l'))
# Position of first and last occurrence of 'because'
sentence = 'You cannot end a sentence with because because because is a conjunction'
print(sentence.find('because'))
print(sentence.rindex('because'))
# Slice out 'because because because'
start = sentence.find('because')
end = sentence.rindex('because') + len('because')
print(sentence[start:end])
# Does it start with Coding? End with coding?
print(company.startswith('Coding'))
print(company.endswith('coding'))
# Remove left and right trailing spaces
trimmed = ' Coding For All '.strip()
print(trimmed)
# isidentifier()
print('30DaysOfPython'.isidentifier()) # False
print('thirty_days_of_python'.isidentifier()) # True
# Join libraries with a hash and space
libraries = ['Django', 'Flask', 'Bottle', 'Pyramid', 'Falcon']
print(' # '.join(libraries))
# Newline escape sequence
print("I am enjoying this challenge.\nI just wonder what is next.")
# Tab escape sequence
print("Name\tAge\tCountry\tCity\nAsabeneh\t250\tFinland\tHelsinki")
# String formatting: area of a circle
radius = 10
area = 3.14 * radius ** 2
print("The area of a circle with radius {} is {:.0f} meters square.".format(radius, area))
# Arithmetic operations with formatting
a, b = 8, 6
print(f'{a} + {b} = {a + b}')
print(f'{a} - {b} = {a - b}')
print(f'{a} * {b} = {a * b}')
print(f'{a} / {b} = {a / b:.2f}')
print(f'{a} % {b} = {a % b}')
print(f'{a} // {b} = {a // b}')
print(f'{a} ** {b} = {a ** b}')