php -a
python
import rlcompleter
import readline
readline.parse_and_bind("tab: complete") #
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
export PYTHONSTARTUP="${HOME}/.pyrc"
export PYTHONIOENCODING="UTF-8"
source ~/.bashrc
foreach($a as $value) {
$formatted = $value.'%';
echo $formatted;
}
:for value in a:
formatted = value + '%'
print(formatted)
, ! . , , . - , , . . Style Guide, -.
print '0.60' * 5;
print '5' == 5;
$a = array('5'=>true);
print $a[5];
$value = 75;
print $value.'%';
$a='0';
if($a) print 'non zero length'; //
, , , PHP 7. , .
>>> print "25" + 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
try:
custom_price = int(request.GET.get('custom_price', 0))
except ValueError:
custom_price = 0
$tak = '';
echo " $tak {$tak}.";
echo " ".$tak.".";
echo sprintf(" %s %1$'.9s.", $tak);
etot = ''
var = ''
print(' %s ' % etot)
print(etot + ' , ')
print(' %s %s' % (etot, var))
print(' %(etot)s %(var)s' % {'etot': etot, 'var': var}) #
print(' {} {}'.format(etot, var))
print(' {1} {0}'.format(var, etot))
print(' {etot} {var}'.format(var=var, etot=etot))
print(f' {etot} {var}') # Python 3.6
strpos($a, 'tr');
trim($a);
vsa.index('tr')
a.strip()
substr($a, strpos($a, 'name: '));
vsa[a.index('name: '):]
>>> len(' ')
19
>>> len(u' ')
10
PHP 6, .
PHP, , MBString function overloading , , . , .
$a = 'Hello.\n';
$a[strlen($a)-1] != "\n";
a = r'Hello.\n'
a[-1] != '\n'
var_dump([0=>1, 'key'=>'value']);
array , PHP array ( ), ( , ). PHP , SPLFixedArray. , , .
a = [1, 2, 3] #
a[10] = 11 #
# > IndexError: list assignment index out of range
a.append(11) #
del a[0] #
a.remove(11) #
d = {'a': 1, 'b': 2, 'c': 3} #
d[10] = 11 #
d[True] = False # (, , , , )
del d[True] #
t = (True, 'OK', 200, ) #
t[0] = False #
# > TypeError: 'tuple' object does not support item assignment
del t[True] #
# > TypeError: 'tuple' object doesn't support item deletion
t = ([], ) # (, , , , )
t[0].append(1)
# > a == ([1], )
s = set([1,3,4])
s[0] = False #
# > TypeError: 'set' object does not support indexing
s.add(5) #
s.remove(5) #
#
s | s #
s & s #
s - s #
s ^ s #
def is_prime(number):
max_number = int(sqrt(number))
for multiplier in range(2, max_number + 1):
if multiplier > max_number:
break
if number % multiplier == 0:
return False
return True
from tools.logic import is_prime
print(is_prime(79))
function makeyogurt($flavour, $type = "acidophilus")
{
return "Making a bowl of $type $flavour.";
}
vsdef makeyogurt(flavour, ftype="acidophilus"):
return "Making a bowl of %s %s." % (ftype, flavour, )
function sum(...$numbers) {
$acc = 0;
foreach ($numbers as $n) {
$acc += $n;
}
return $acc;
}
echo sum(1, 2, 3, 4);
//
echo add(...[1, 2, 3, 4]);
def acc(*args, **kwargs):
total = 0
for n in args:
total += n
return total
print(acc(1, 2, 3, 4))
#
print(acc(*[1, 2, 3, 4]))
class BaseClass:
def __init__(self):
print("In BaseClass constructor")
class SubClass(BaseClass):
def __init__(self, value):
super(SubClass, self).__init__()
# , Python 3.6: super().__init__()
self.value = value
def __getattr__(self, name):
print("Cannot found: %s" % name)
c = SubClass(7)
print(c.value)
Source: https://habr.com/ru/post/221035/
All Articles