Quick actions

cmd+k|ctrl+k

Navigation

Languages

initial

Snippet info

Language

Python

Visibility

public

Author

cyrilobeng7

Created

2025-01-11T23:07:23.886303Z

Updated

2025-01-11T23:08:11.796659Z

print("Hello World!")

# formatted strings 

name = 'Johnny'
age = 55 

print('hi ' + name + '. You are ' + str(age) + ' years old') 

# Writing the same code with formatted string 

print(f' hi {name} . You are {age} years old')

# Using the .format() method from python 2

print(' hi {} . You are {} years old'.format('Jonny', '55'))

# using variables 

print('hi {} . You are {} years old' .format(name, age))

# Using indexing 

print('hi {0} . You are {1} years old'.format(name, age))

# creating new variables 
print('Hi {new_name} . You are {age} years old'.format(new_name='Sally', age=100))

# String Indexes 

selfish = 'me me me'
        #  01234567
        
print(selfish[0])

print(selfish[7])

selfish = '01234567'
        #   01234567
        
print(selfish[0])

print(selfish[7])




INFO