It gives the character that is represented by the ASCII code "34".
If you look up an ASCII table you will notice that 34 = "
Answer from Loocid on Stack OverflowIt gives the character that is represented by the ASCII code "34".
If you look up an ASCII table you will notice that 34 = "
The %c is a format character gives the character representation. For example consider the following statements
>>> print "%c" % 'a'
a
>>> print ("%c" % 97)
a
>>> print "%c" %'"'
"
>>> print "%c" %34
"
>>> print "%c" %'asdf'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %c requires int or char
Breaking up
"%c" % 34 == '"'
would be like
>>> "%c" % 34
"
>> '"' == '"'
True
How to use the -c flag in python - Stack Overflow
Cannot figure out what the "c" stands for
iterator - Meaning of a python statement with "next( c for c in l if )" - Stack Overflow
python - What does the c underscore expression `c_` do exactly? - Stack Overflow
It gives the character that is represented by the ASCII code "34".
If you look up an ASCII table you will notice that 34 = "
Answer from Loocid on Stack OverflowJust pass regular Python code as the argument to the flag:
python -c 'print 1
print 2'
Import modules works, and blank lines are OK, too:
python -c '
import pprint
pprint.pprint(1)
'
When using this feature, just be mindful of shell quoting (and indentation), and keep in mind that if you're using this outside of a few shell scripts, you might be doing it wrong.
Easiest example
python -c "print 'example'"
It is useful whenever your program has a single line of code, for example, list comprehensions, etc.
Another example can be
python -c "a='example';print a"
As you can see, multiple statements are separated by ;
str_var = "A string" count = 0 for c in str_var: count += 1 print(count)
can anyone explain what the "c" stands for in this? Does it stand for character? (Code came from a learning software I am using)
It's combining two-arg next (which pulls the next value from an iterator, and if the iterator is exhausted returns the second argument as the default) with a generator expression, which is like a lazy list comprehension (it produces an iterator/generator that produces values on demand).
So:
r = next((c for c in l if config.equalsForConfigSet(c)), None)
in English, means "Get the first element of l for which config.equalsForConfigSet of that element is truthy; if no such element is found, return None". And it does it lazily, or if you prefer, with short-circuiting, so as soon as one c value passes, it doesn't need to continue; the rest of l isn't even loaded, let alone tested (unlike how a list comprehension would do it).
In code, you could express the same behavior with a function like so:
def firstEqualsConfigSet(l, config):
for c in l:
if config.equalsForConfigSet(c):
# Short-circuit: got one hit, return it
return c
# Didn't find anything
return None # Redundant to explicitly return None, but illustrating
# that two-arg next could use non-None default
then use the function to do:
r = firstEqualsConfigSet(l, config)
My understanding is
next(iterator, default) The next() function returns the next item from the iterator.
its taking 'c' from the for loop which is extracting c from the list l (populated earlier), wherein the for loop is evaluating with a condition that config.equalsForConfigSet(C) should return true.
If there is no value for 'c' in the first parameter to next(), it will return None
https://www.programiz.com/python-programming/methods/built-in/next
It took me a lot of time to understand but it seems I finally got it.
All you have to do is add along second axis.
let's take :
np.c_[np.array([1,2,3]), np.array([4,5,6])]
But there isn't second axis. So we mentally add one.
so shape of both array becomes (3,1).
So resultant shape would be (3,1+1) which is (3,2). which is the shape of result -
array([[1, 4],
[2, 5],
[3, 6]])
Another ex.:
np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
shapes:
np.array([[1,2,3]]) = 1,3
np.array([[4,5,6]]) = 1,3
0 so we can think of it as [[0]] = 1,1
So result 1,3+1+1+3 = 1,8
which is the shape of result : array([[1, 2, 3, 0, 0, 4, 5, 6]])
Use IPython's ? syntax to get more information:
In [2]: c_?
Type: CClass
Base Class: <class 'numpy.lib.index_tricks.CClass'>
String Form:<numpy.lib.index_tricks.CClass object at 0x9a848cc>
Namespace: Interactive
Length: 0
File: /usr/lib/python2.7/dist-packages/numpy/lib/index_tricks.py
Docstring:
Translates slice objects to concatenation along the second axis.
This is short-hand for ``np.r_['-1,2,0', index expression]``, which is
useful because of its common occurrence. In particular, arrays will be
stacked along their last axis after being upgraded to at least 2-D with
1's post-pended to the shape (column vectors made out of 1-D arrays).
For detailed documentation, see `r_`.
Examples
--------
>>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
array([[1, 2, 3, 0, 0, 4, 5, 6]])
I was always curious how python modules in c work. I know how to write and use a python c module, but i dont know how it works internally. Can anyone put me in the right path where can i start, an article or sthm or try to explain. And are there any simple tutorials to implement that sort of thing. Like calling .so files from your language etc...