Cómo crear cadena en Python
string = "this is string"
#or
string = 'this is also string'
PENGUIN OVERLORD
string = "this is string"
#or
string = 'this is also string'
#1) To type a string using the keyboard module:
#pip install keyboard
import keyboard
string = "This is what I typed"
keyboard.write(string)
#2) To check if an object is of the type 'str' (to check if the object is a string):
if type(object) == str:
#3) To print a string:
string = "This is displayed in your Big Black Console"
print(string)
#Strings in python are surrounded by either single quotation marks, or double quotation marks.
print("This is a string")
print('i am also a string')
string = 'amaama'
half = int(len(string) / 2)
if len(string) % 2 == 0: # even
first_str = string[:half]
second_str = string[half:]
else: # odd
first_str = string[:half]
second_str = string[half+1:]
# symmetric
if first_str == second_str:
print(string, 'string is symmertical')
else:
print(string, 'string is not symmertical')
# palindrome
if first_str == second_str[::-1]: # ''.join(reversed(second_str)) [slower]
print(string, 'string is palindrome')
else:
print(string, 'string is not palindrome')
>>> 'Py' 'thon'
'Python'
#You can assign a multiline string to a variable by using three quotes:
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)