Un résumé de l'apprentissage personnel! J'ai appris la grammaire de base de trois langues, alors je les ai résumées!
Ruby
puts "Hello, world"
Python
print("Hello, world")
PHP
echo "Hello, world";
Ruby
variable = "variable"
Python
variable = "variable"
PHP
$variable = "variable";
Ruby
# attr_accessor :Définissez le getter par son nom, etc.
puts person.name
Python
# def __init__Définissez un getter avec etc.
print(person.name)
PHP
echo $person->name();
Ruby
if number % 15 == 0
puts "FizzBuzz"
elsif number % 3 == 0
puts "Fizz"
elsif number % 5 == 0
puts "Buzz"
else
puts number
end
Python
if number % 15 == 0:
print("FizzBuzz")
elif number % 3 == 0:
print("Fizz")
elif number % 5 == 0:
print("Buzz")
else:
print(number)
PHP
if (number % 15 == 0){
echo "FizzBuzz";
} elseif (number % 3 == 0){
echo "Fizz";
} elseif (number % 5 == 0){
echo "Buzz";
} else {
echo $number;
}
Ruby
#Tableau
array = ["rouge", "Bleu", "Jaune"]
#hacher
hash = {"Préfecture d'Osaka": "Osaka", "Préfecture d'Aichi": "Nagoya", "Tokyo": "Tokyo?"}
Python
#liste
lists = ["rouge", "Bleu", "Jaune"]
#dictionnaire
dict = {"Préfecture d'Osaka": "Osaka", "Préfecture d'Aichi": "Nagoya", "Tokyo": "Tokyo?"}
PHP
//Tableau
$array = ["rouge", "Bleu", "Jaune"];
//Tableau associatif
$associative_array = [
"Préfecture d'Osaka" => "Osaka",
"Préfecture d'Aichi" => "Nagoya",
"Tokyo" => "Tokyo?"
];
Ruby
i = 1
while i <= 100 do
#En traitement
i += 1
end
Python
i = 1
while i <= 100:
#En traitement
i += 1
for i in range(1, 101):
#En traitement
PHP
for ($i = 1;$i <= 100;$i++){
//En traitement
}
Ruby
array.each do |value|
#En traitement
end
hash.each {|key, value|
#En traitement
}
Python
for value in lists:
#En traitement
for key in dict:
#En traitement
PHP
foreach($array as $value){
//En traitement
}
foreach($associativeArray as $key => $value){
//En traitement
}
Ruby
def hello
#En traitement
end
Python
def hello():
#En traitement
return #Valeur de retour
PHP
function hello() {
//En traitement
return //Valeur de retour
}
Ruby
class Person
@@number = 0
def self.classmethod
#En traitement
end
def initialize(name)
@name = name
end
person = Person.new("Yamada")
end
Python
class Person:
number = 0
@classmethod
def classmethod(cls):
#En traitement
def __init__(self, name):
self.name = name
end
person = Person("Yamada")
end
PHP
class Person {
private static $number;
private $name;
public function static function classmethod(){
echo self::$number;
}
public function __construct($name){
$this->name = $name;
}
$person = new Person();
}
Ruby
def setName(name)
@name = name
end
def getName
@name
end
#Ou
attr_accessor :name
Python
def __init__(self, name):
self._name = name
@property
def name(self):
return self.__name
@name.setter
def name(self, name):
self.__name = name
PHP
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
On a l'impression qu'il y a une personnalité dans la façon de spécifier un bloc (end / indent / {})! Merci pour la lecture! : détendu:
Recommended Posts