You are Here:
Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section



int(3) and int('3') is there a difference? (python3.5)

Author (Read 11608 times)

0 Members and 1 Guest are viewing this topic.

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #12 on: April 05, 2019, 10:00:16 AM »
 

freemedia2018

  • New to Forums
  • *
  • 6
    Posts
  • Reputation: 2
  • Linux Lite Member
    • View Profile
    • digital literacy for everyone

  • CPU: varies

  • VIDEO CARD: not nvidia
Python is one of my favourite languages.

I think they only mentioned int('2') to demonstrate that int() can convert string data to integer data.

Quote
So its a string that can be added, multiplied, divided etc?

No, a string is more like a list of characters. If you multiply a string by a number, you get a string:

Code: [Select]
print("l" + "ol" * 5)
An integer is a numeric value that rounds to the nearest whole number. If you multiply an integer by another numeric value, you get a numeric value.

Code: [Select]
print(2.7 * 5)
type is a great command in Python. Here are some things you can try:

Code: [Select]
>>> type('5')

>>> type(5.0)

>>> type(int(5))

>>> type(int('5'))

>>> type(str(5))

>>> int('5.0')

>>> float('5.0')

>>> type(float('5.0'))

>>> int(float('5.0'))
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #11 on: February 06, 2019, 05:54:57 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
I use paper copies of the books too, I find pdf's very hard to use when learning but read other books as these. So tend to use the paper books. I have this stand for whichever book I use it has two bars to hold it open on the page you choose I put this next to the monitor to its right then I can read from it and the screen, with no light or info changes on screen. It has been really useful. You can tilt the angle of it there are steps/slots at the back and a bar to slot in to whichever angle you want.
Cracking Codes with Python is interesting it has a lot of historical information of how code was used for privacy and the methods. One day I'll get around to going to visit Bletchley Park, I liked the Drama show about it too. It was where they cracked the codes in WW2, one group of the crackers were all women.

Other Python books I have are -
The definitive Guide Series - Python - the beginners guide, I have used a fair amount of this.
Make games with Python - it is a Raspberry Pi book, available free as a pdf too, on MagPi website.
Think Python - O'Reilly
My partner got me these ones at christmas and said to do them in this order after all of the first books above -
Effective Computation in Physics
Learning Python
Programming Python
Python Pocket Reference

The Learning & Programming Python books are aka "the pink kettle bells", as this is what I was told was inside the box, my extraction of info is obviously in serious need of improvement based on that fail lol.
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #10 on: February 06, 2019, 05:20:06 PM »
 

teage

  • New to Forums
  • *
  • 5
    Posts
  • Reputation: 1
  • Linux Lite Member
    • View Profile

  • MEMORY: 4Gb
I think when you want to jump forward it is a good sign you are enjoying learning Python and find it interesting. :)
On inventwithpython url which book are you using ?
I like Al Sweigart books a lot, he is a really good teacher for Python, I have these books by Al Sweigart -Automate the boring stuff with Python - (it is the best first book to use to learn Python imo), I am using Chapter 2 of this book.Invent your own computer games with Python - I am using Chapter 5 of this book. (another good first choice book)
Cracking codes with Python - just looked at Chapter 1, I had to wait for some tools to make the wheels nicely. Making games with Python and Pygame - I haven't looked at this yet it is for doing last of the first books, I am not in to games, I like code, and to see results so it's an easy way to do that etc.

Online the majority I read recommended Zed Shaw - Learn Python the Hard way, I have the Python2 version, I am on Chapter 17 of this book, but have not been using it since I began with the other books, later I will return to it. Personally I don't like this book he has a nasty attitude, that is distracting/disruptive.

The 2 chapters of Automate the boring stuff with Python & 5 chapters of Invent your own computer games with Python were enough to start making my first software/apps, it was where I began trying this.It took me 1+ year to complete the first app, from idea to finished how I was happy with it as a first one.

It's possible to do projects at the same time as learning, and in between using the books, whenever you feel like it, or have an idea you want to try out for fun, plus you can learn extra things doing your projects, it is all practice.

I am reading (Invent Your Own Computer Games with Python, 4th Edition). I like this book a lot. So much so that I bought a paper back copy on amazon. I am not much into games but the book is excellent and easy to understand. My son will love it he is very technical. I wish I had these resources when I was young  ::). I am interested in the cracking codes book too maybe I will check it out sometime down the road.
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #9 on: February 06, 2019, 05:10:26 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
I'm definitely using the method 2 approach.  I have gotten about half way through Zeds book,( learn python the hard way ) about a year ago. He started to lose me just wasn't clicking. Since then I have found an interactive book I plan to read as soon as I'm done with these others. I'm all over the place.

I use method 2 also, by "my method" I mean it is belonging to whoever uses it, not me personally, even though I use this way too.
Method 2 is organic, free flowing and malleable, its a good way to learn.
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #8 on: February 06, 2019, 04:35:01 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
I think when you want to jump forward it is a good sign you are enjoying learning Python and find it interesting. :)
On inventwithpython url which book are you using ?
I like Al Sweigart books a lot, he is a really good teacher for Python, I have these books by Al Sweigart -
Automate the boring stuff with Python - (it is the best first book to use to learn Python imo), I am using Chapter 2 of this book. 
Invent your own computer games with Python - I am using Chapter 5 of this book. (another good first choice book)
Cracking codes with Python - just looked at Chapter 1, I had to wait for some tools to make the wheels nicely.
Making games with Python and Pygame - I haven't looked at this yet it is for doing last of the first books, I am not in to games, I like code, and to see results so it's an easy way to do that etc.
Online the majority I read recommended Zed Shaw - Learn Python the Hard way, I have the Python2 version, I am on Chapter 17 of this book, but have not been using it since I began with the other books, later I will return to it. Personally I don't like this book he has a nasty attitude, that is distracting/disruptive.

The 2 chapters of Automate the boring stuff with Python & 5 chapters of Invent your own computer games with Python were enough to start making my first software/apps, it was where I began trying this.

It took me 1+ year to complete the first app, from idea to finished how I was happy with it as a first one.
It's possible to do projects at the same time as learning, and in between using the books, whenever you feel like it, or have an idea you want to try out for fun, plus you can learn extra things doing your projects, it is all practice.
« Last Edit: February 06, 2019, 05:13:03 PM by bitsnpcs »
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #7 on: February 06, 2019, 03:54:56 PM »
 

teage

  • New to Forums
  • *
  • 5
    Posts
  • Reputation: 1
  • Linux Lite Member
    • View Profile

  • MEMORY: 4Gb
I'm definitely using the method 2 approach.  I have gotten about half way through Zeds book,( learn python the hard way ) about a year ago. He started to lose me just wasn't clicking. Since then I have found an interactive book I plan to read as soon as I'm done with these others. I'm all over the place.
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #6 on: February 06, 2019, 03:06:15 PM »
 

teage

  • New to Forums
  • *
  • 5
    Posts
  • Reputation: 1
  • Linux Lite Member
    • View Profile

  • MEMORY: 4Gb
I'm actually reading two books, http://inventwithpython.com which has been so far vey easy to understand and follow, and I'm also reading the html version of five into python 3 that is installed under my docs folder. I agree I'm most likely jumping the gun a bit maybe the answer will come full circle as I progress through the book.
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #5 on: February 06, 2019, 11:16:23 AM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x

 
Different ways to learn code, or learn most things.
Method one looks so boring. The branches dont really do much.
Method 2 looks alive, each dot is the outcomes of the chaos merging to form a result/project you do whilst learning , notice how the branches all go somewhere , they have a use, and a result. In reality most people will have huge numbers of strands on the image 2.
Method2 is good way to increase the pace of learning compared to Method1, the central line are the book/s you are learning from.


« Last Edit: February 06, 2019, 11:22:25 AM by bitsnpcs »
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #4 on: February 05, 2019, 10:22:33 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
So its a string that can be added, multiplied, divided etc?

forgive me if my questions seem a bit silly, im just trying to wrap my head around it. :o



In this example yes.
Int can be used to convert a value into a number (an integer), then the calculations can be done on it etc.
The value can be one of any of the types.

What book are you using ?
It may be you are experimenting further than the current chapter covers, and things will be explained in more detail in future chapters.
You might need a faster paced book, or enjoy to make some projects extra to the book so you can experiment.

I am learning Python2, one book I use Python Crash Course by Eric Matthes I learn Python2 and Python3 along side, I am only on Chapter 3 of it, as I have been busy lately so only had time for 1 book to use for learning and that has been the Linux Command Line.
For when I complete my Python2 books, the first Python3 book I have and will use is called "O'Reilly Head First Python".
« Last Edit: February 06, 2019, 12:01:37 AM by bitsnpcs »
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #3 on: February 05, 2019, 09:50:53 PM »
 

teage

  • New to Forums
  • *
  • 5
    Posts
  • Reputation: 1
  • Linux Lite Member
    • View Profile

  • MEMORY: 4Gb
Hello teage,
it can be used apostrophes where the integer is to print within a string using the speech marks " "

There is an example here  https://www.programiz.com/python-programming/methods/built-in/int


So its a string that can be added, multiplied, divided etc?

example 1 of the url shows,
# integer
print("int(123) is:", int(123))

# float
print("int(123.23) is:", int(123.23))

# string
print("int('123') is:", int('123'))

so then I experiment with this,

>>> int('2')+int('2')
4

>>> int("2")+int("2")
4

>>> int(2)+int(2)
4

forgive me if my questions seem a bit silly, im just trying to wrap my head around it. :o
 

Re: int(3) and int('3') is there a difference? (python3.5)
« Reply #2 on: February 05, 2019, 09:26:07 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
Hello teage,
it can be used apostrophes where the integer is to print within a string using the speech marks " "

There is an example here  https://www.programiz.com/python-programming/methods/built-in/int
 

int(3) and int('3') is there a difference? (python3.5)
« Reply #1 on: February 05, 2019, 08:50:43 PM »
 

teage

  • New to Forums
  • *
  • 5
    Posts
  • Reputation: 1
  • Linux Lite Member
    • View Profile

  • MEMORY: 4Gb
So I'm reading a python3 book and working with int(). I follow the directions everything is fine. They have me typing in the shell int('2') and see the result. I noticed if I type int(2) with no apostrophe i get the same result. So my question is this, is there a difference?
 

 

-->
X Close Ad

Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section