Questions tagged as 'python'

2
answers

Encoding utf-8 allows accents?

If we do # encoding: utf-8 In the first line of a Python program, can we make accents in the whole code?     
asked by 05.06.2015 / 03:01
3
answers

How to write multiple rows in Python?

How can I write a string with multiple lines in Python? As I come from PHP, I usually do this: $string = " uma linha outra linha2 " Or: $string = <<<EOT uma linha outra linha EOT; When I try to do this in Python, it...
asked by 13.08.2015 / 14:47
3
answers

Set constant in Python

How can I declare a Python constant in the same way I do in C with #Define PI 3.1415 or in java public final double PI = 3.1415     
asked by 05.04.2017 / 21:35
4
answers

Count occurrences in a list according to prefixes

Let's imagine that I have a list ['rato', 'roeu', 'rolha', 'rainha', 'rei', 'russia'] and another list with prefixes ['ro', 'ra', 'r'] How do I count how many times each prefix is within the first list?     
asked by 07.04.2015 / 23:10
2
answers

Is it possible to name a parameter when the function is called?

Can I "access" a specific parameter of a JavasScript function, ie give a value for a given parameter? As an example is better than text (since I can not explain myself right), here's one: In Python, having a function: def funcX(A="A",B="B",...
asked by 28.01.2015 / 15:36
2
answers

How to capture the last element of a list in Python?

In PHP, to get the last element of an array I can do this: $array = array(1, 2, 3); echo end($array); // 3; What about Python? How could I do this with this list: arr = [1, 2, 3]     
asked by 09.01.2017 / 19:28
2
answers

Count the number of occurrences of a value in a list

I have list with the following values: numeros = [5, 3, 1, 2, 3, 4, 5, 5, 5] In Python would have some function to count how many times some value repeats? For example: I want to know how many times 5 has repeated.     
asked by 09.01.2017 / 20:04
2
answers

What is the difference between 'string' and r'string 'in Python?

I was looking at the code in Django, framework in Python, and I came across the following code in the file urls.py . urlpatterns = [ url(r'^articles/2003/$', views.special_case_2003), url(r'^articles/([0-9]{4})/$', views.year_a...
asked by 13.08.2015 / 14:29
1
answer

What is a Prototyping Language?

Reading an article on the internet, I came across the following excerpt:    Python, by its more general proposal, is a great choice as    Prototyping language for systems constructed in, say, more bureaucratic languages such as C, C ++, C #,...
asked by 10.11.2015 / 19:19
2
answers

Is it good practice to always manage errors with exceptions?

I'm creating a game with Python 3.4 and Pygame, and I'm using the object-oriented paradigm. In my classes, especially in __init__ , I'm full type checkings , to prevent runtime errors. For example, this is my class Board...
asked by 09.12.2014 / 01:22