2019-02-08 05:37:23

when I writing this code and try to run in terminal still no result show up
below is my code:
#casting specific type

#int type
x = int(1)
y = int(3.02)
z = int("4")

#string type
gender = str("male, female")
gpax = str(2.87)

thanks for helping me figure out

the bestest reward for people who are working so hard they should receive their experience of their own life.
everyone can collect in everyday.
:d

2019-02-08 05:59:37

Hi,
To see the output, you will need to use  print function. Like this:
print(x)
x is the variable. You can print any text or variable using it.
Regards,
Amit

There once was a moviestar icon.
Who prefered to sleep with the light on.
They learnt how to code, devices sure glowed,
and lit the night using python.

2019-02-08 12:50:17

yep. I was gonna say. All you are currently doing is setting and changing variables. print is required to actually get the output. Also keep in mind that print I believe will throw an error if you try to directly print the integers. I tend to use f before the stream, like so
print(f "{x}, {y}, {z}")
no more concatenating! Woo!

Much less active on this forum than in the past.

Check out my live streams: http://lerven.me
follow me on Twitter: http://twitter.com/liamerven

2019-02-09 04:36:27

@3, you can use print("{0} {1} {2}.format(a, b, c)) instead which is more readable

2019-02-09 09:28:22

I would argue that print(f) with everything in one stream is more readable as you are then not having to look at the right hand part of the stream to remember like 0 1 2 and 3 and 4 and 17 and 25 are. When you start doing a number of substitutions the .format method can be frustrating. That being said though, Python's formatting methods really extend it's power when handling text. It's one of my favorite things about the language.

Much less active on this forum than in the past.

Check out my live streams: http://lerven.me
follow me on Twitter: http://twitter.com/liamerven

2019-02-09 14:12:38

@4, you can as well omit the index number. Something like this would  also work, but I don't know if it will be readable
print('{} {}'.format(1, 2,))
I don't think format() is more readable than f"", I just think it's a preference. F it's probably more easier to use if you have difficulty remembering the position of the variable that you want to replace in the string.
If though you're writing a program from backward compatibility then format() should be used.

Paul

2019-02-09 18:05:35

Originally when I started learning Python I learned the .format method, but found it was too rigid if I wanted to quickly change a variable. Again. Totally personal preference. The good thing about Python and most any other language as you can accomplish the same task in several different ways.

Much less active on this forum than in the past.

Check out my live streams: http://lerven.me
follow me on Twitter: http://twitter.com/liamerven