#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Learning python basics


    Hello Everybody:

    I am new to python, but am familiar with the basic of programming languages. I am following some tutorials online. I am not sure if the tutorials are for an older version, because most of the stuff doesn't work for me. for example, using variables:

    Code:
    #!/usr/bin/python cars = 100 print cars
    when I run this, it says invalid syntax.
    i am running IDLE 3.3.0 and python version 3.3.0.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    16
    Rep Power
    0
    I do not know how it is in the version "3", but you can not declare variables in the same line as a comment.

    Try this

    Code:
    #!/usr/bin/python
    
    cars = 100
    print cars
    or

    Code:
    #!/usr/bin/python
    
    cars = 100
    print "cars"
    or

    Code:
    #!/usr/bin/python
    
    cars = 100
    print 'cars'
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    8
    Rep Power
    0
    Had the same problem while trying some code

    try #!/usr/bin/python

    cars = 100
    print(cars)
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,850
    Rep Power
    481
    nicnad post is correct for python 3. In python 3 print is a function rather than a statement, as it is in earlier pythons.


    #!/usr/bin/python

    cars = 100
    print(cars)
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Santa Clara, CA
    Posts
    5
    Rep Power
    0
    There is also some useful information and boards for beginners in python programming over at @veriously

IMN logo majestic logo threadwatch logo seochat tools logo