xuv's notebook

Side notes, howtos and random bits of information related to Julien Deswaef's projects

User Tools

Site Tools


workshops:blender:python_basics

This is an old revision of the document!


Python basics

Variables

Python variables are very easy to set up and very flexible.

a = 10
print(a)
# 10
 
a = 2.5
print(a)
# 2.5
 
a += a
print(a)
# 5.0
 
a = [ 1, 2, 3, 4, 5 ]
print( a[2] )
# 3
 
len(a)
# 5
 
a = "hello"
a += " world"
print(a)
# hello world
 
len(a)
# 11
 
print(a[10])
# d

So we just saw here that creating a variable is just writing its name and giving it a value. The type of value does not matter. And the variable will accept any type of value even if it's different from the one it use to have before.

Useful things

Commenting:

# The most common way of commenting. 
print ("hello")  # Works only for whatever is after the # tag.
# Works only on a single line
 
'''
Multi line commenting is done this way.
It's actually creating a multi-line String.
But not assigning it to any variable.
Works well if you want to comment multi lines of code.
'''
workshops/blender/python_basics.1434821865.txt.gz · Last modified: 2015/06/20 19:37 by Julien Deswaef