10 Ways to Write Hello Python
1. Basic print statement
print ( ” H e l l o Python ” )
2. Using a function
def s a y h e l l o ( ) :
print ( ” H e l l o Python ” )
say hello ()
3. Using f-string
name = ” Python ”
print ( f ” H e l l o {name}” )
4. Using format method
print ( ” H e l l o {} ” . format ( ” Python ” ) )
5. Using string concatenation
print ( ” H e l l o ” + ” Python ” )
6. Using lambda function
h e l l o = lambda : print ( ” H e l l o Python ” )
hello ()
1
7. Using a class method
class Greeter :
def g r e e t ( s e l f ) :
print ( ” H e l l o Python ” )
g = Greeter ()
g . greet ()
8. Using a list comprehension
[ print ( ” H e l l o Python ” ) f o r in range ( 1 ) ]
9. Using a while loop
i = 0
while i < 1 :
print ( ” H e l l o Python ” )
i += 1
10. Using a generator function
def h e l l o g e n ( ) :
y i e l d ” H e l l o Python ”
f o r g r e e t i n g in h e l l o g e n ( ) :
print ( g r e e t i n g )