1

I am trying to print a text with the name too.

from faker import Faker
fake = Faker()
name = fake.name()

print(name)

but i want it to print some plain text as well in that print.

like Hello, my name is: < Fake Name Generated Above >

Raahim Fareed
  • 501
  • 7
  • 17
Johnyy
  • 11
  • 1
  • 2

6 Answers6

2

Fancier, do:

print(f'Hello my name is {name}.')

1

There are multiple ways you can do that

# f-strings
print(f"Hello, my name is: {name}")

# Str.format()
print("Hello, my name is: {name}".format(name))

# Concatenation
print("Hello, my name is: " + name)

# Simple print
print("Hello, my name is: ", name)

You can choose whichever one you prefer the most.

Raahim Fareed
  • 501
  • 7
  • 17
0

Do:

print("Hello, my name is:", name)
NameKhan72
  • 717
  • 4
  • 11
0

You could try directly printing the string and variable (comma separated) or use the string format()

from faker import Faker
fake = Faker()
name = fake.name()

print("Hello, my name is:",name)

#or
your_text="Hello my name is: "
print("{your_text} {name}".format(yourtext, name))
Jay
  • 110
  • 10
0

You could also declare a new variable in which you concatenate the text and the name. Then you can print that. This might be useful if you are using this text multiple times.

For example:

name = fake.name()
text = "Hello, my name is: " + name

this would only work if the name is a string. if it is not you would have to add the str() function.

For example:

name = fake.name()
text = "Hello, my name is: " + str(name)
0

Not sure why Powershell was tagged but, heres how you do it in Posh:

#Keeping the string an object
Write-Output "Hello World"
#or:
"Hello World"

#Printing to screen
Write-Host "Hello world"

#With Color
Write-Host "Hello World" -ForeGroundColor Red

#in a variable
$String = "Hello World"

#To print the variable
$String




Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24