Mixed data types in strings


#1

So it would work like this? Big_string = " I loved to eat" + str(pancakes) "when i was " + str(18)

??? Please help me :cold_sweat:


Can I use more than one type conversion at once?
#2

Let’s break this down and discuss the minutea…

Big_string

It will take a while to be able to fully explain, but we should not capitalize variable names. There is a convention in Python (and other languages, as well) where a capital letter will indicate that the object is a Class. Like I said, not able to fully explain. The course will lead up Classes, where it will all unfold. For now, just adopt the convention and only use lower case.

big_string

Looks like the space character is on the wrong end of the string.

"I loved to eat "

You’ll learn ways to format a string without imposing white space, but for now, what you have is adequate. The trailing space will prevent the next item in the concatenation from crowding the previous word.

str(pancakes)

This is a whole can of worms, to be honest. First, what object and data type does pancake refer to? The grammar of the opening phrase would indicate a noun, which would be a string, so the str() function would be unnecessary. That’s what the grammar hints at, anyway.

The data type could be a number, which would need to be converted in order to concatenate to a string. It could even be a list,

str(['pancakes', 'apple pie', 'banana splits'])

At any length, pancakes needs to be defined, given these considerations.

The only minor issue here is the missing leading space to prevent this phrase from crowding whatever pancakes is.

Hope you don’t mind we went to town on your code. Take from it what you may. Keep asking questions as you progress.