"First off, interpreted/compiled is not a property of the language but a property of the implementation (...) Python is compiled. Not compiled to machine code ahead of time (i.e. "compiled" by the restricted and wrong, but also common definition), "only" compiled to to bytecode" on stackoverflow
Python 2 and Python 3 are version with separate evolution.
Migrate Python 2 to Python 3 can be a difficult task.
In Mac or Linux system operatives we have already Python installed. In Windows we must install it.
Variables
In Python we don't have a explicit variables declaration, they just exist when we give them a value.The declaration rules are sneak case, like a_name_to_variable.
We can attribute values at the same time, like, one_variable_value, two_variable_value = 22, 45
String variable
A String in Python can be declared as ' ' or " ", example: string_in_python = 'example' or example: string_in_python = "example".We can have just a part of string like, [0:4] (slice operator). This will give the value string from position 0 to 4.
Number can be integer, float, long and complex
A Integer value in Python can be declared as int_in_python = 2A Long can be declared as <number>L, example: long_in_python = 12L
A Complex number can be declared as <number>j, example: long_in_python = 12,21j
List
The content of a list can be any type value.
You declare a list as list_names = ['jean', 'bubu ugly', 'justin'].
You declare a list as list_names = ['jean', 'bubu ugly', 'justin'].
To access to a value just use list_names [0].
You can add a new value (from any type) like list_names.append('another name').
You can remove a value like list_names.remove('another name'). Please not that you must indicate the exact value.
dict_example['key1'] = value1
dict_example.keys() will give you all keys contained
dict_example.values() will give you all values contained
Tuple
Tuple structure is immutable, you can't append a value like you can do on list structures.
tuple_example = ('tuple1', value1, 'tuple2', value2)
tuple_example[1] = value1
tuple_example[0:2] = ['tuple1','value1']
tuple_example[1] = value1
tuple_example[0:2] = ['tuple1','value1']
Dictionary
dict_example = {'key1' : value1, 'key2' : value2}dict_example['key1'] = value1
dict_example.keys() will give you all keys contained
dict_example.values() will give you all values contained
Concatenation
You can't concatenate a string with a int number on a message, for example:'This is a ' + string_in_python + ' with a ' + int_in_python
This must be like
'This is a %s with a %s' % (string_in_python, int_in_python)
Functions/Methods
We don't delimit a function using {} like on other languages. We use identation and the function name with two points like:
function_name():
// line code here
// line code here
// etc
Import some functions from specific modules just use:
from module_name import * (* we will import all from module_name)
To import a specific function just use:
from module_name import the_function
Sem comentários:
Enviar um comentário